Mert Nuhoglu
Mert Nuhoglu

Reputation: 10133

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

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?

Upvotes: 13

Views: 5512

Answers (1)

zgoda
zgoda

Reputation: 12895

Single namespace: yes. Single module: no.

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

Upvotes: 8

Related Questions