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('.')
eugene
  • 39,839
  • 68
  • 255
  • 489
  • 1
    Try adding `from profiles import *` to `myApp/models/__init__.py` and then using `AUTH_USER_MODEL = 'myApp.MyModel'` – DanielB Oct 31 '13 at 05:29
  • I get different error "ImproperlyConfigured: AUTH_USER_MODEL refers to model 'common.CusomUser' that has not been installed" – eugene Oct 31 '13 at 05:43
  • 1
    oh shoot me.. Cus T om User.. – eugene Oct 31 '13 at 05:55
  • I've posted my information as an answer. You should accept whichever helped you for the sake of anyone who lands here from Google :) – DanielB Oct 31 '13 at 06:03

2 Answers2

5

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.

DanielB
  • 2,798
  • 1
  • 19
  • 29
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.

tuxcanfly
  • 2,494
  • 1
  • 20
  • 18