Multiple Django Apps using one database/model
New to Django...I'm trying to create a project with the following structure:
CompanyName <--Project
ingredients < -- Application
CompanyName
supplier <-- Application
My issue is that my project is going to use a database/model like the following:
suppliers (table)
- name
- created_by (foreign_key, auth.User)
ingredients (table)
- name
- supplied_by (foreign_key, supplier.name)
My question is do I create all the tables in a single models.py or do I break up each table into each application's manage.py? If I use separate models.py, how do you create the suppliers table and then the ingredients table since the ingredients table has a foreign key to suppliers?
Here's my thought:
- You can create both in the same models.py. You should separate it into a separate app when it has special and complete functionality.
- You can refer to a forigen key found in another app. See here (4th example): https://docs.djangoproject.com/en/3.2/ref/models/fields/#foreignkey This will not cause you a problem because the tables are not created until you run:
makemigrations
migrate