3

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 ?

  • 1
    what 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
  • 1
    oh.. you just need to import from where it is defined. example `from import User` – karthikr Nov 11 '14 at 20:48
  • 1
    possible 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 Answers1

-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