4

I have myApp/models/profiles.py instead of myApp/models.py (to group related models)

How do you set AUTH_USER_MODEL in this case?

Because auth accepts only "foo.bar" pattern.

   app_label, model_name = settings.AUTH_USER_MODEL.split('.')
4

2 回答 2

4

Django expects the models for any given app to be in app.models. If you want to use this kind of file structure, you'll need to still make sure this is the case. The easiest way to do this is too add from profiles import * in myApp/models/__init__.py and then use AUTH_USER_MODEL as normal.

For example, you you had myApp/models/profiles.py and myApp/models/actions.py your myApp/models/__init__.py should read

from profiles import *
from actions import *

Remember to make sure you don't have any name conflicts too, and you may wish to use set your __all__ value in each of your sub-packages.

于 2013-10-31T06:02:56.213 回答
0

You can either pass the class directly or the 'app.model'. django only registers classes defined in app.models module, so you'll need to import the class in models init. Since you'll be importing the model in init anyway, you don't need to specify the full path to the class in the foreignkey.

于 2013-10-31T05:34:32.250 回答