Split Django Models Into Multiple Files (Same App)

In larger Django projects, the models.py file can become difficult to maintain.
A simple solution is to split models into multiple files while keeping them in the same app.

 

mysite
    polls
        models
            __init__.py
            models1.py
            models2.py

 

 

  1. Remove models.py from the polls app
  2. Create a folder called models
  3. Inside the models folder create __init__.py(empty file)
  4. Create the required models for your project

 

python manage.py makemigrations
python manage.py migrate

 


Django