Django magic removeral still support models in multiple files?

3 views
Skip to first unread message

favo

unread,
May 31, 2006, 3:23:47 AM5/31/06
to Django users
I have check the document about Model, but can't find any help about
models in multiple files.
Django magic removeral still support models in multiple files?
only we can do is write models in models.py??

favo

unread,
May 31, 2006, 5:47:50 AM5/31/06
to Django users
I put code in directory structure below,
appsname\
models\
__init__.py
model1.py # have a class named Model1

__init__.py :
__all__ = ['model1']
from Model1 import model1

I have see the code in django.db.model.ModelBase.__new__ and find why
django MR don't support the multiple model files.

__new__ :
if getattr(new_class._meta, 'app_label', None) is None:
# Figure out the app_label by looking one level up.
# For 'django.contrib.sites.models', this would be 'sites'.
new_class._meta.app_label =
model_module.__name__.split('.')[-2]
...
register_models(new_class._meta.app_label, new_class)

in my example, the model_module is "project.appsname.models.model1"
so the new_class._meta.app_label is "models" rather than "appsname".

so register models to 'models' not to 'appsname'.

I remember that django 0.91 support the multi models file.
can any develop fix it?

favo

unread,
May 31, 2006, 7:08:59 AM5/31/06
to Django users
Reply all
Reply to author
Forward
0 new messages