Skip to content

Default selected option for LookupChoiceFilter ? #1619

Answered by Kagee
Kagee asked this question in Q&A
Discussion options

You must be logged in to vote

Solution: empty_label=None,

I could get no version of inital to work.

After having read hundreds of documentation pages and source code lines for both Django and django-filters i found that this will work - there will be no empty option element, and the first tuple in lookup_choices will be the top of the list. It will not have the selected HTML attribute, but still works.

If this is how it is supposed to be done i strongly suggest it is added to the documentation, optionally the correct way.

class OrderItemFilter(django_filters.FilterSet):
      name = django_filters.LookupChoiceFilter(
           lookup_choices=(
              ('icontains', 'Contains'),
              ('istartswith', 'St…

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Kagee
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Kagee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants