ModelMultipleChoiceFilter - wrong field format in request url
See original GitHub issueHi,
I am using django-filters
ModelMultipleChoiceFilter
. I am running into a problem where values from the input field are not correctly converted to the django-filters format, i.e. filter_field=value_1&filter_field=value_2&...
. The value from the input field is treated as one value (none of the separators seem to work, the format of query params in request is like filter_field=value_1,value_2,...
).
The filter that I have looks something like this:
from django_filters import rest_framework as filters
from django.contrib.auth.models import User
class TeamFilterSet(filters.FilterSet):
members = filters.ModelMultipleChoiceFilter(
label=_('Filter by member IDs'),
field_name='members',
queryset=User.objects.all(),
)
Is it possible to obtain the expected format in the request url or do I have to override the actual filter to get the proper values from the request?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
DRF ModelMultipleChoiceFilter - invalid value in one of many ...
I looked a bit at the django_filters code and it seems like there's no configuration/option to make the ModelMultipleChoiceFilter field do ...
Read more >Filter Reference — django-filter 22.1 documentation
RangeWidget – this widget is used with RangeFilter to generate two form input elements using a single field. ModelChoiceFilter and ModelMultipleChoiceFilter ...
Read more >django-filter Documentation - Read the Docs
Filters no longer autogenerated when Meta.fields is not specified . ... We need a URL pattern to call the view:.
Read more >django-filter Documentation - Yumpu
ModelChoiceFilter, the queryset argument has callable behavior. To use a custom field name for the lookup, you can use to_field_name: class FooFilter( ...
Read more >How do I use Django-filter with multiple values on the ... - Quora
It seems like an odd request to me, but let's go with it. Starting off, filtering a model based on a field is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, this solution works! Thank you so much for your help!
ahh now i get it! the schema you receive comes from
django-filter
itself. they generate a filter schema themselves but that is pretty much useless almost all of the time because they don’t have the introspection tooling we have.our extension does not active as it is a different class. we can match subclasses but it is safer not to by default when you do custom stuff.
simply define a new extension based on the existing one. this should do it for you
edit fyi: https://drf-spectacular.readthedocs.io/en/latest/faq.html#where-should-i-put-my-extensions-my-extensions-are-not-detected