Ticket #19060: customuser.diff

File customuser.diff, 872 bytes (added by ivan_virabyan, 2 years ago)

don't expect custom user model to be called User

  • django/contrib/auth/backends.py

    diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
    index d103f32..934c3e3 100644
    a b class ModelBackend(object): 
    3030            if user_obj.is_superuser:
    3131                perms = Permission.objects.all()
    3232            else:
    33                 perms = Permission.objects.filter(group__user=user_obj)
     33                related_query_name = get_user_model()._meta.get_field('groups').related_query_name()
     34                filters = {'group__%s' % related_query_name: user_obj}
     35                perms = Permission.objects.filter(**filters)
    3436            perms = perms.values_list('content_type__app_label', 'codename').order_by()
    3537            user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms])
    3638        return user_obj._group_perm_cache
Back to Top