Home > Django > Code bloat in your Django projects: Models

Code bloat in your Django projects: Models

My current project’s getting a bit large, so I figured I should start subdividing the code a bit. The project’s already split up into multiple applications, but my main application is growing…

The first thing I’ve done is split up my models.py into multiple files and moved them into a folder named models.

Folder structure is: project/application/models/model_file.py

All that’s left to be done is to add an _init_.py to that folder and import all your models within the __init__.py. You’ll also need to make sure the app_label set on each of your models.

For example:
class Shape(models.Model):
value = models.CharField ()
class Meta:
app_label = "my_project"

This may turn into a series…lets see if there’s anything else that needs better organization.

Categories: Django Tags:
  1. No comments yet.
  1. No trackbacks yet.