I Django can 2 apps share 1 model, or 2 apps must define the same model inside. so app1 and app1 can have have same products model inside them for example?
Yes, app1
and app2
can share the same model. You need to import it wherever you want to use it.
Lets say your project structure is like below having 2 apps app1
and app2
.
my_project/
manage.py
my_project/
__init__.py
settings.py
urls.py
wsgi.py
app1/
__init__.py
admin.py
migrations/
__init__.py
models.py
tests.py
views.py
app2/
__init__.py
admin.py
migrations/
__init__.py
models.py
tests.py
views.py
Then to use the models defined in app1/models.py
in app2
, you just need to do:
from app1.models import MyModel # import the model
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With