2👍
Two Scoops of Django suggests breaking out models into individual apps which is a pattern I have followed for many years and have had no issues with. Only as of recently I started creating a core
app where I put all the models (as well as common functionality) into a models/
directory and inside the directory I have each model in its own individual file. I especially prefer this new pattern early on when starting a project because it is hard to tell where is the best place to put each model. I have run into the problem multiple times during work where I put a model in one spot and only after the project matured did I realize it could and should be in a different location. I take the same approach with serializers for the models except I put them in an api
app and inside theapp I have another serializers/
directory.
Another reason I prefer this approach is because I think in general it is cleaner. Instead of having 5 lines of code for importing models:
from app1.models import App1Model
from app2.models import App2Model
from app3.models import App3Model
from app4.models import App4Model
from app5.models import App5Model
App1Model.objects.create(...)
You can import all the models in one line:
from core import models as core_models
core_models.App1Model.objects.create(...)
0👍
To me I’d combine related models (that won’t be useful when separated) together in one app.
In your example you have:
Petition,
Cause for the petition and
Signatures for this petition
Any of these models is useless when used alone. (i.e can’t have petition without cause and can’t have cause without petition).
User model on the other hand doesn’t require petition to be useful, it can be used in other parts of the project and so I’d keep it separate.
If Recipient has no use case outside petition and only referenced there, I’d add it also to the petition models. I’d call the app petitions.
That being said if you are making a simple app that is all about petition and won’t be expanded then my comment may not make much sense and in fact I think it won’t matter much what u do for such a simple app
- [Answered ]-Store two types of value in single Django model field
- [Answered ]-Filter JSON data in TextField