Why does django enforce all model classes to be in models.py?

帅比萌擦擦* 提交于 2019-12-22 03:16:57

问题


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?


回答1:


Single namespace: yes. Single module: no.

Your models have to be importable from namespace appname.models.



来源:https://stackoverflow.com/questions/1339040/why-does-django-enforce-all-model-classes-to-be-in-models-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!