When using django-filters , how can I set the initial value of a field in my filter?
Usually with a standard form in Django, for example, a simple selection list form:
class MyForm(forms.Form):
OPTIONS=(('APP','Apple'),('BAN','Banana'))
country = forms.ChoiceField(widget=forms.Select(),
choices=OPTIONS, initial='BAN')
to initialize writing forms to Banana. However, in mine filter.py, if I have something like:
class MyFilter(django_filters.FilterSet):
OPTIONS=(('APP','Apple'),('BAN','Banana'))
myfield = django_filters.ChoiceFilter(
widget=django_filters.widgets.forms.Select(),choices=OPTIONS)
.
.
where do I put initial='BAN'to get the initially selected item in the dropdown list, etc.? I tried the arguments ChoiceFilterand to Select()no avail.
, Filters , Forms , , , ( ) .