I am new in Django and I don't know how to deal with sharing models problem. For simplicity assume that we have two apps: A1, A2 and one model M1. Now I would like to A1 and A2 are using the same model M1. I probably can put M1 inside A1 and A2 but this is not good idea. How to deal with this ?
Asked
Active
Viewed 2,043 times
3
-
1what do you mean be `using the same model` ? How are the relationship defined? Is it a foreign key, or a many to many, or do both contain the fields specified in `m1` ? – karthikr Nov 11 '14 at 20:39
-
For example i have table User and i want to use it as model in django in A1 and A2. Should i define this model twice in A1 and A2 models.py file or do something else to achieve this ? – Dawid Skrzypczyński Nov 11 '14 at 20:44
-
1oh.. you just need to import from where it is defined. example `from
import User` – karthikr Nov 11 '14 at 20:48 -
1possible duplicate of [Sharing models between Django apps](http://stackoverflow.com/questions/4137287/sharing-models-between-django-apps) – David Dahan Nov 11 '14 at 20:48
1 Answers
-1
define M1
in app A1
or A2
and use like this in another app models.py
:
from A1.models import M1

Hasan Ramezani
- 5,004
- 24
- 30
-
1Thanks this is some solution but when I will have 10 apps then i will have to remember where i define this model. Better solution would be some folder where i would put common models. – Dawid Skrzypczyński Nov 11 '14 at 21:06
-
1
-
But that common directory needs to be a django app or normal directory. Otherwise how will we make migrations. – Adarsh Trivedi Aug 09 '18 at 11:18