Skip to content

Commit

Permalink
Fix admin filter in Django 5
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed Mar 29, 2024
1 parent 1144c43 commit d0027dc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django_jalali/admin/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import jdatetime
import django
from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -75,8 +76,12 @@ 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):
params = self.used_parameters.copy()
if django.VERSION > (5, 0):
params = {k: v[0] if isinstance(v, list) else v for k, v in params.items()}

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

Expand Down

0 comments on commit d0027dc

Please sign in to comment.