djangodjango-modelsdjango-profiles

AUTH_PROFILE_MODULE value in django when the models is not a file but a directory


I had the following: (it worked as expected)

# In <..>/profile/models.py
class UserProfile()
#In settings.py
AUTH_PROFILE_MODULE = "profile.UserProfile"

I have the following: (not working)

# In <..>/profile/models/__init__.py
class UserProfile()
AUTH_PROFILE_MODULE = "profile.UserProfile"

It seems that get_profile() calls get_model which is looking for models.py as a file and trys to load it.

Here is the error:

raise SiteProfileNotAvailable('Unable to load the profile ' SiteProfileNotAvailable: Unable to load the profile model, check AUTH_PROFILE_MODULE in your project settings

The reason is that I have lot of classes in the profile app and they are all in different files and imported in:

<..>/profile/models/__init__.py

This works for everything else but the get_profile().

Any hint of a workaround?


Solution

  • sometimes django will get confused about appnames, so make sure you have:

    class UserProfile(Model):
        ....
        class Meta:
            app_label = 'profile'
    

    This will make sure the profile can be looked up with profile.UserProfile