Code

Ticket #19060: customuser.diff

File customuser.diff, 872 bytes (added by ivan_virabyan, 22 months ago)

don't expect custom user model to be called User

Line 
1diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
2index d103f32..934c3e3 100644
3--- a/django/contrib/auth/backends.py
4+++ b/django/contrib/auth/backends.py
5@@ -30,7 +30,9 @@ class ModelBackend(object):
6             if user_obj.is_superuser:
7                 perms = Permission.objects.all()
8             else:
9-                perms = Permission.objects.filter(group__user=user_obj)
10+                related_query_name = get_user_model()._meta.get_field('groups').related_query_name()
11+                filters = {'group__%s' % related_query_name: user_obj}
12+                perms = Permission.objects.filter(**filters)
13             perms = perms.values_list('content_type__app_label', 'codename').order_by()
14             user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms])
15         return user_obj._group_perm_cache