views:

262

answers:

3

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  A: 

Check out http://stackoverflow.com/questions/1160579/models-py-getting-huge-what-is-the-best-way-to-break-it-up

Kyle Kochis
Thanks for the reference. It seems that there are two solution proposals:1. CookBook's Splitting models across multiple files approach: http://code.djangoproject.com/wiki/CookBookSplitModelsToFiles2. splitting into many interdependent small apps.I think the former one seems easier.
Mert Nuhoglu
+1  A: 

You should read PJ Eby's classic blog entry: Python is not Java.

Daniel Roseman
Thanks for this valuable reference. It is very instructive. But there is one thing missing in this article. The author deals mostly differences in coding practices between python and java. What I would really like to learn are design differences between python and java applications. For example, in java it is customary to use hibernate as orm framework which is totally noninvasive. But this is not true for django's orm. I am sure there are valid rationalizations for this difference. I wonder whether there are good articles that explain such differences in architectural decisions.
Mert Nuhoglu
+1  A: 

Single namespace: yes. Single module: no.

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

zgoda