Last active
December 4, 2020 17:16
-
-
Save peterfarrell/ad7103e366a929b5665c73c762012a74 to your computer and use it in GitHub Desktop.
Defaults for Django-Filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DocumentFilterSet(FilterSet): | |
period = django_filters.ChoiceFilter( | |
choices=Periods.choices, | |
label='Period', | |
field_name='period', | |
method='period_filter', | |
) | |
def period_filter(self, queryset, name, value): | |
if value: | |
return queryset.filter(period=value) | |
else: | |
return queryset.filter(period='default_period') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment