#268 Filter multiple parcelgroups

* adds filter support for multiple parcelgroup and district names, separated by ','
This commit is contained in:
mpeltriaux 2022-12-08 10:14:39 +01:00
parent 0901bb8d76
commit a06b960435

View File

@ -19,7 +19,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
Specialized on filtering GeoReferenced model types
"""
# Parcel gmrkng
# District
di = django_filters.CharFilter(
method="filter_district",
label=_(""),
@ -72,7 +72,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
),
)
# Parcel counter
# Parcel number
pn = django_filters.NumberFilter(
method="filter_parcel_number",
label=_(""),
@ -112,7 +112,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
return queryset
def filter_district(self, queryset, name, value) -> QuerySet:
""" Filters queryset depending on value for 'Gemarkung'
""" Filters queryset depending on value for 'Kreis'
Args:
queryset ():
@ -122,10 +122,13 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
Returns:
"""
matching_districts = District.objects.filter(
Q(name__icontains=value) |
Q(key__icontains=value)
).distinct()
values = value.split(",")
q = Q()
for val in values:
val = val.strip()
q |= Q(name__icontains=val) | Q(key__icontains=val)
matching_districts = District.objects.filter(q).distinct()
matching_parcels = Parcel.objects.filter(
district__in=matching_districts
)
@ -148,9 +151,14 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
Returns:
"""
values = value.split(",")
q = Q()
for val in values:
val = val.strip()
q |= Q(parcel_group__name__icontains=val) | Q(parcel_group__key__icontains=val)
queryset = self._filter_parcel_reference(
queryset,
Q(parcel_group__name__icontains=value) | Q(parcel_group__key__icontains=value),
q,
)
return queryset