diff --git a/pyproject.toml b/pyproject.toml index a6b4b18..4760917 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django-smartbase-admin" -version = "1.0.33" +version = "1.0.34" description = "" authors = ["SmartBase "] readme = "README.md" diff --git a/src/django_smartbase_admin/engine/filter_widgets.py b/src/django_smartbase_admin/engine/filter_widgets.py index f858d85..dc1299e 100644 --- a/src/django_smartbase_admin/engine/filter_widgets.py +++ b/src/django_smartbase_admin/engine/filter_widgets.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta from django.core.exceptions import ImproperlyConfigured +from django.contrib.postgres.fields import ArrayField from django.db.models import Q, fields, FilteredRelation, Count from django.http import JsonResponse from django.utils import timezone @@ -212,6 +213,8 @@ def get_default_label(self): return found_label[0] if found_label else default_value def get_base_filter_query_for_parsed_value(self, request, filter_value): + if isinstance(self.model_field, ArrayField): + return Q(**{f"{self.field.filter_field}__contains": [filter_value]}) return Q(**{self.field.filter_field: filter_value}) @@ -248,6 +251,11 @@ def __init__( self.select_all_label = select_all_label def get_base_filter_query_for_parsed_value(self, request, filter_value): + if isinstance(self.model_field, ArrayField): + q_objects = Q() + for value in filter_value: + q_objects |= Q(**{f"{self.field.filter_field}__contains": [value]}) + return q_objects return Q(**{f"{self.field.filter_field}__in": filter_value}) def get_advanced_filter_operators(self):