为 Django MVT 项目记录 UML class 图

Documenting UML class diagrams for a Django MVT project

为使用 MVT 设计模式的 Django 项目创建 UML class 图的最佳方法是什么,尤其是在项目中使用基于函数的视图时?将视图视为 classes 是否正确,即使它们是基于函数的?我混合使用了基于 class 和基于函数的视图,因此该选项看起来很方便,但我不确定从技术角度来看这是否正确。另外,我可以将模板视为 classes 吗?

是的,在 UML 中,您可以将带有 class 的独立函数表示为

我不知道 django,MVT, but it appears that by its official definition a view 也不是可调用的:

A view is a callable which takes a request and returns a response. This can be more than just a function, and Django provides an example of some classes which can be used as views. These allow you to structure your views and reuse code by harnessing inheritance and mixins.

因此在这种情况下,甚至建议将其表示为 class,因为该函数是更一般的 class 可调用对象的特例。

django template 似乎由文件(数据)定义,可用于实例化 Template 对象。所以你的项目的每个模板最终都会成为一个不同的对象,并且应该只有一个 Template class.

来自 django 模型的 UML - 请检查这个

https://simpleit.rocks/python/django/generate-uml-class-diagrams-from-django-models/