13

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?

Mert Nuhoglu
  • 9,695
  • 16
  • 79
  • 117
  • Your link is dead. Could you please update it ? – Gabriel Apr 30 '16 at 13:29
  • Possible duplicate of [models.py getting huge, what is the best way to break it up?](http://stackoverflow.com/questions/1160579/models-py-getting-huge-what-is-the-best-way-to-break-it-up) – Ajoy Jun 06 '16 at 04:32

1 Answers1

8

Single namespace: yes. Single module: no.

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

zgoda
  • 12,775
  • 4
  • 37
  • 46
  • I think this answer is probably the correct answer to this question, but it could certainly do with being made clearer. I think it basically boils down to `appname.models` needs to import all the models from other modules. An explanation of why, or where this behaviour is documented would be helpful. – SpoonMeiser Dec 21 '15 at 12:08
  • Similarly, why would having `appname.models` just import the modules that define other models not be sufficient? Surely that would trigger the necessary metaclass magic? If not, why? – SpoonMeiser Dec 21 '15 at 12:10