From fe5ff57466ce80b7c82f44d2e545f06a2401abae Mon Sep 17 00:00:00 2001 From: Rik Date: Thu, 30 Sep 2021 22:42:18 +0200 Subject: [PATCH] support custom user model without user groups If no user groups exist, don't query it, so that when you use a custom user model without groups, that you don't get an error. Relevant GitHub Issue: https://github.com/modlinltd/django-advanced-filters/issues/57 --- advanced_filters/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced_filters/models.py b/advanced_filters/models.py index 33f1b28..d72a422 100644 --- a/advanced_filters/models.py +++ b/advanced_filters/models.py @@ -15,7 +15,8 @@ class UserLookupManager(models.Manager): def filter_by_user(self, user): """All filters that should be displayed to a user (by users/group)""" - + if not hasattr(user, 'groups'): + return self.filter(users=user) return self.filter(Q(users=user) | Q(groups__in=user.groups.all()))