1 2 3 4 5 6 7 8 9 10 11 | from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from model_utils.managers import InheritanceQuerySet
class CustomUserModelBackend(ModelBackend):
def get_user(self, user_id):
try:
return InheritanceQuerySet(User).select_subclasses().get(pk=user_id)
except User.DoesNotExist:
return None
|
More like this
- convenience parent class for UserProfile model by willhardy 4 years ago
- ModelMixin by eallik 2 years, 6 months ago
- Access transparently the user profile information by gsakkis 2 years, 8 months ago
- Prefill ForeignKey caches by insin 4 years, 7 months ago
- Improved User Admin by gregb 3 years ago
Comments
Hello,
I'd really like to use it. How should I deploy it?
Thanks in anticipation.
#
Well, first you put the above code in a backends.py file.
Then, in your settings.py, put the following:
Then you can do something like this in one of your models.py:
#