Skip to content

Commit

Permalink
Fix admin filter in Django 5 (slashmili#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed Oct 20, 2024
1 parent 6fc8473 commit b904ae0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions django_jalali/admin/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
import jdatetime
from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters
Expand Down Expand Up @@ -75,18 +76,31 @@ def __init__(self, field, request, params, model, model_admin, field_path):
super().__init__(field, request, params, model, model_admin, field_path)

def queryset(self, request, queryset):
used_parameters = self.used_parameters.copy()
if django.VERSION > (5, 0):
used_parameters = {
k: v[0] if isinstance(v, list) else v
for k, v in used_parameters.items()
}

try:
return queryset.filter(**self.used_parameters)
return queryset.filter(**used_parameters)
except ValidationError as e:
raise IncorrectLookupParameters(e)

def expected_parameters(self):
return [self.lookup_kwarg_since, self.lookup_kwarg_until]

def choices(self, cl):
date_params = self.date_params
if django.VERSION > (5, 0):
date_params = {
k: v[0] if isinstance(v, list) else v for k, v in date_params.items()
}

for title, param_dict in self.links:
yield {
"selected": self.date_params == param_dict,
"selected": date_params == param_dict,
"query_string": cl.get_query_string(param_dict, [self.field_generic]),
"display": title,
}
Expand Down

0 comments on commit b904ae0

Please sign in to comment.