Reputation: 3163
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.
Upvotes: 1
Views: 76
Reputation: 55932
I like to create an app called common
which includes utilities, basemodels, utility base test classes that all (or multiple apps) share.
You can create a common
app and just put the models.py
file in there. As long as you register it you can use manage.py syncdb
and just import its classes where you need them.
Upvotes: 2