为什么django将所有模型类都执行为models.py? [英] Why does django enforce all model classes to be in models.py?

查看:152
本文介绍了为什么django将所有模型类都执行为models.py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚了解到,将模型类分成不同的文件会破坏django的许多内置功能。



我来自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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆