I want to share a models.py between several applications. The database tables should be created from models.py using manage.py. Django 1.4 standard directory structure is:
myproject
|
|-- manage.py
|-- myproject
| |
| -- settings.py
| -- urls.py
|-- myapp1
| |
| -- models.py
| -- views.py
|-- myapp2
|
-- models.py
-- views.py
What’s the best way to change this dir structure to achieve what I want? Put models.py in myproject dir, put a file models.py in myapp1 which only imports everything from the former models.py and use “manage.py syncdb” to create the db tables? Is there a way to get the same result without the 2nd models.py?
Thanks in advance.
I like to create an app called
commonwhich includes utilities, basemodels, utility base test classes that all (or multiple apps) share.You can create a
commonapp and just put themodels.pyfile in there. As long as you register it you can usemanage.py syncdband just import its classes where you need them.