Coverage for apps/campaigns/filters.py: 88%
12 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-08 12:47 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-08 12:47 -0600
1import django_filters
3from base.utils import get_subclass_as_dict
5from .models import Campaign
8class CampaignFilter(django_filters.rest_framework.FilterSet):
9 ctype_dict = get_subclass_as_dict(Campaign)
11 campaign_type = django_filters.ChoiceFilter(
12 method="campaign_type_filter",
13 choices=list(ctype_dict.items()),
14 )
16 def campaign_type_filter(self, queryset, name, value):
17 selected_campaign_type = self.ctype_dict[value] if value in self.ctype_dict.keys() else None
18 return queryset.instance_of(selected_campaign_type)
20 class Meta:
21 model = Campaign
22 fields = ["campaign_type", "status", "organization"]