Django-filter: For ModelMultipleChoiceFilter query_parms if given null gives empty result

Created on 17 May 2017  ·  3Comments  ·  Source: carltongibson/django-filter

class filter(filters.FilterSet):
    filename = django_filters.CharFilter(name='filename', lookup_expr='contains')
    state = django_filters.filters.ModelMultipleChoiceFilter(
                                                             name='state_id',
                                                             to_field_name ='state' ,
                                                             queryset=models.IngestionState.objects.all())

http://localhost:8000/ingestion-detail/?filename="{something}"&status=

The above URL gives empty result.
Only when status = {something} we are getting the required result. This is case specific to ModelMultipleChoiceFilter only

Most helpful comment

from django_filters.constants import STRICTNESS this showing me error called ImportError: cannot import name 'STRICTNESS'

All 3 comments

Well, difficult to help with what you've said.

'status' != 'state' but I assume that's a typo.

Try from django_filters.constants import STRICTNESS and set the strict meta option to STRICTNESS.RAISE_VALIDATION_ERROR. That should at least tell you something.

Otherwise I'll need you to try and identify something much more specific before I can consider this an Issue. Maybe StackOverflow would suit you better if you just need help.

HI,I had the same problem , in this situation ,how to fix the empty result if ,my url had the status=blank, if i want the status in all possible?

from django_filters.constants import STRICTNESS this showing me error called ImportError: cannot import name 'STRICTNESS'

Was this page helpful?
0 / 5 - 0 ratings