Hello all,
I’m upgrading from Django 4.2.8 to 5.0.2.
Please consider the following filter:
from django.contrib import admin
class TestFilter(admin.SimpleListFilter):
title = "Test"
parameter_name = "vertrag"
def lookups(self, request, model_admin):
return (
("ok", "gültig"),
("ausg", "ausgeschieden"),
("unbek", "unbekannt"),
)
def queryset(self, request, queryset):
# With Django 4.2, this printed "ok", "ausg" or "unbek".
# With Django 5.0, this prints "k" or "g".
print(self.value())
if self.value() == "unbek":
# Never gets here with Django 5.0.2.
return queryset.filter(profile__ma__isnull=True)
else:
return queryset
With Django 4.2.8, the following test case succeeded:
queryset = User.objects.filter(username="abc")
for value in ("ok", "ausg", "unbek"):
filt = TestFilter(None, {"vertrag": value}, User, LoriUserAdmin)
self.assertEqual(
filt.queryset(None, queryset).count(),
1 if value == "unbek" else 0,
)
With Django 5.0.2, I must wrap the value
string in a tuple:
# ...
filt = TestFilter(None, {"vertrag": (value,)}, User, LoriUserAdmin)
# ...
Maybe this is related to the item in the release notes about the changes to the …FieldListFilter
classes, but I’ve not been able to figure out if this change was introduced intentionally?