Skip to content

Instantly share code, notes, and snippets.

@peterfarrell
Last active December 4, 2020 17:16
Show Gist options
  • Save peterfarrell/ad7103e366a929b5665c73c762012a74 to your computer and use it in GitHub Desktop.
Save peterfarrell/ad7103e366a929b5665c73c762012a74 to your computer and use it in GitHub Desktop.
Defaults for Django-Filters
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