Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 582
Mert Nuhoglu Avatar asked Aug 27 '09 05:08

Mert Nuhoglu


People also ask

What is the purpose of the models py file in Django?

Django web applications access and manage data through Python objects referred to as models. Models define the structure of stored data, including the field types and possibly also their maximum size, default values, selection list options, help text for documentation, label text for forms, etc.

What is the purpose of the models py file?

Model.py is one of the most import concept of django framework. It allows us to completely define the database of our web applications allowing us to : Declare tables and fields of our database. Define all meta-data of our Database.

What is a model in Django and what is the model class?

Django models simplify the tasks and organize tables into models. Generally, each model maps to a single database table. Each model is a Python class that subclasses django.


1 Answers

Single namespace: yes. Single module: no.

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

like image 172
zgoda Avatar answered Sep 21 '22 00:09

zgoda