[Answered ]-Django filter OrderingFilter default choice

1👍

The fix was to disable the empty option by setting the empty_label and null_label to None. This was the first option is the default option. Note, the first option should algin with the default ordering of your queryset so that it matches when loading the page without using a filter.

class MyFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(lookup_expr='icontains')

    o = django_filters.OrderingFilter(
        choices=(
            ('created', _('Created, old to new')),
            ('-created', _('Created, new to old'))
        ),
        fields = (
            'created', 'created'
        ),
        empty_label = None,
        null_label = None
    )
    

Leave a comment