Coverage for apps/products/filters.py: 88%
12 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-04-19 09:45 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-04-19 09:45 -0600
1import django_filters
3from app.utils import get_subclass_as_dict
5from .models import Product
8class ProductFilter(django_filters.rest_framework.FilterSet):
9 ctype_dict = get_subclass_as_dict(Product)
11 resourcetype = django_filters.ChoiceFilter(
12 method="resourcetype_filter",
13 choices=list(ctype_dict.items()),
14 )
16 def resourcetype_filter(self, queryset, name, value):
17 selected_resourcetype = self.ctype_dict[value] if value in self.ctype_dict.keys() else None
18 return queryset.instance_of(selected_resourcetype)
20 class Meta:
21 model = Product
22 fields = ["resourcetype"]