How to organize a Django project with abstract models

I have several models: "Article, Video, BlogPost, News, Commodity". Each of them is in its own application.

All of them are basically the same models with several additional fields on each. But each share is about 15 fields. I am using an abstract base class . I am trying to understand how I should do this organization for this. My current setup is this:

apps/ abstract_models.py abstract_templatetags.py abstract_forms.py articles/ models.py ... videos/ models.py ... blogs/ ... 

Although I know that this is not a very good way, I just do not know where to post all the information that is shared. I do it this way, and then the application simply subclasses the form or model and makes local modifications. Since this is just a small number of changes compared to the whole picture, I think the abstract class is the way to go, but I could be wrong.

They share so much structure, but for obvious reasons, I would like to leave them separate applications. But I would like to clean it a little.

Any thoughts would be greatly appreciated.

+4
source share
2 answers

I am setting up an application that I can use in different projects and call it tools . In tools , I have basic basic models that I prefer to use in different projects and import where necessary.

For example, I have CreatedModifiedModel in tools/models.py , which adds fields for creation and modification time, as well as the user who created and modified.

Once determined once, I can simply do:

 from tools.models import CreatedModifiedModel class Widget(CreatedModifiedModel): # comes with my four fields automatically 

You can create one application called base or core or tools , and then place all your abstract classes there to keep it clean and make it reusable in the future.

+4
source

The Pinax project has something similar to bands. They made their base class and those that distribute it to the application.

 /apps /group base.py ... /projects models.py ... 

It seems to be great to organize. You can see their source code on github.

+1
source

All Articles