Opened 11 years ago

Closed 11 years ago

#7400 closed (wontfix)

Auth: get_profile() doesn't allow other name than user for foreign key

Reported by: contato@… Owned by: nobody
Component: Contrib apps Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Django's authentication framework get_profile() method doesn't allow another name than 'user' to foreign key field in user profile class, like:

class UserProfile(models.Model):
  another_name = models.ForeignKey(User, unique=True)

If I try to get the user profile with user.get_profile(), it generates an exception.

Error is in the get_profile method where it try to get the profile cache, getting by self._profile_cache = model._default_manager.get( The problem is where it had to be or anything else.
File django/contrib/auth/

    def get_profile(self):
        Returns site-specific profile for this user. Raises
        SiteProfileNotAvailable if this site does not allow profiles.
        if not hasattr(self, '_profile_cache'):
            from django.conf import settings
            if not settings.AUTH_PROFILE_MODULE:
                raise SiteProfileNotAvailable
                app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
                model = models.get_model(app_label, model_name)
                self._profile_cache = model._default_manager.get( # <-- where error happens
            except (ImportError, ImproperlyConfigured):
                raise SiteProfileNotAvailable
        return self._profile_cache

Change History (1)

comment:1 Changed 11 years ago by Jacob

Resolution: wontfix
Status: newclosed

This is just how profiles work: it's an application of duck typing. There's plenty of other ways to get from a User to some custom profile object; get_profile is for one particular common case.

Note: See TracTickets for help on using tickets.
Back to Top