views:

191

answers:

2

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?

+5  A: 

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.

Baresi
Thanks for your reply, especially the link to the blogpost.
Alasdair
+1  A: 

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

kibitzer