Created
September 9, 2012 00:05
-
-
Save jarcoal/3681395 to your computer and use it in GitHub Desktop.
Simple Extension to Django's default ModelBackend to force it to select a profile in addition to the user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AUTHENTICATION_BACKENDS = ('project_name.wherever.you.put.it.SmartModelBackend',) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.backends import ModelBackend | |
from django.contrib.auth.models import User | |
class SmartModelBackend(ModelBackend): | |
def get_user(self, user_id): | |
try: | |
#note that 'profile' needs to be set to whatever your profile's related_name is. | |
return User.objects.select_related('profile').get(pk=user_id) | |
except User.DoesNotExist: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment