After reading monokrome's answer to Where should Django manager code live?, I've decided to split a large models.py
into smaller, more manageable files. I'm using the folder structure
foodapp/
models/
__init__.py #contains pizza model
morefood.py #contains hamburger & hotdog models
In __init__.py
, I import the models from morefood.py
with
from morefood import hamburger, hotdog
However, when I run python manage.py syncdb
, the only table created is foodapp_pizza
- What do I need to do to get Django to create tables for the models I have imported from morefood.py
?
Try this:
foodapp/ __init__.py models.py /morefood __init__.py hamburger.py hotdog.py
and do this in models.py:
from foodapp.morefood.hamburger import *
from foodapp.morefood.hotdog import *
as suggested in this blogpost.
Or, in your morefood.py models, add the following to the Meta:
class Meta:
app_label = 'foodapp'
Then syncdb will work with your existing structure
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