Skip to content Skip to sidebar Skip to footer

Initial Value Is Not Working For ChoiceField On Django-filters

I've the following django-filter (https://github.com/alex/django-filter/) filter: class ApplicationFilter(django_filters.FilterSet): status = django_filters.ChoiceFilter(choic

Solution 1:

Try this:

def __init__(self, *args, **kwargs):
    super(ApplicationFilter, self).init(*args, **kwargs)
    self.initial['status'] = 'NEW'

Solution 2:

This answer might work for you: Set initial value with django-filters?

In my views, I do:

get_query = request.GET.copy()
if 'status' not in get_query:
    get_query['status'] = 'final'
filter_set = MatterFilterSet(get_query)

Post a Comment for "Initial Value Is Not Working For ChoiceField On Django-filters"