python - Set initial value with django-filters? -


When using an app, how can I set the initial value of the field in my filter?

Usually with a standard form in Django , for example a simple selection list form:

  class MyForm (forms.Form) : Option = (('APP', 'apple'), ('ban', 'banana')) country = forms Start form entry on Choisefield (widget = forms.selection, option = option, initial = 'bann')  

banana However, my I have something like this in filter.py :

  class MyFilter (django_filters.FilterSet): option = (('APP', 'apple'), ('ban', 'Banana')) myfield = django_filters.ChoiceFilter (widget = django_filters.widgets.forms.Select (), option = option). .  

Where to get initially selected element of dropdown, where do I put initial = 'BAN' ? I did not take any advantage of the choisefilter argument and selection () arguments.

I thought the idea of ​​the filter was very clearly the behavior of form with the benefit of filtering clearly, so I Wondering (what I think) does not work in the initial place.

This works for me if a data is not provided in the request then this is a default set Does:

  data = request GET.copy () if LAN (data) == 0: data ['field'] = initial_value filter = MyFilterSet (data)  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -