I've the following filter in my admin.py
file:
class parentCategoryFilter(admin.SimpleListFilter):
title = 'parent category'
parameter_name = 'parent_category'
def lookups(self, request, model_admin):
first_level_categories = model_admin.get_queryset(request).filter(parent_category__isnull=True)
if first_level_categories:
lookups = (('none', 'None'),)
for first_level_category in first_level_categories:
lookups += ((first_level_category.id, first_level_category.name),)
return lookups
def queryset(self, request, queryset):
if self.value() == 'none':
return queryset.filter(parent_category__isnull=True)
elif self.value():
try:
return queryset.filter(parent_category=int(self.value()))
except (ValueError, TypeError):
return queryset.none()
else:
pass
And I want to test it in my tests.py
file, however while trying to instantiate the class it starts asking me about 5 __init__
parameters. Is it possible to test this filter functionality?