为什么django将所有模型类都执行为models.py? [英] Why does django enforce all model classes to be in models.py?
问题描述
我来自java背景。在那里,不被接受为写很长的类文件的好习惯。但是django对所有模型类的单个文件的执行可能会导致程序员编写很长的models.py文件。这将使程序员难以看到整个领域模型的组织。
那么为什么django会强制单个文件来包含所有域类?
我发现解决方案提案通过谷歌搜索这个问题。但是我无法确定这是否能正常工作。你建议这个解决方案吗?
单个命名空间:是的。单个模块:no。
您的模型必须可以从命名空间 appname.models
中导入。
I have just learned that splitting model classes into different files breaks many of django's built-in functionalities.
I am coming from a java background. There, it is not accepted as a good practice writing very long class files. But django's enforcement of single file for all model classes will probably cause programmer to write very long models.py files. This will make it difficult for programmer to see the organization of the whole domain model.
So why does django enforce single file to contain all domain classes?
I have found a solution proposal to this problem by googling. But I cannot be sure whether this will work properly. Do you suggest this solution?
Single namespace: yes. Single module: no.
Your models have to be importable from namespace appname.models
.
这篇关于为什么django将所有模型类都执行为models.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!