Replies: 1 comment 1 reply
-
OK, so then you'll want to define a widget that returns a list of items from the class ManyWiget(Widget):
def value_from_datadict(self, data, files, name):
return data.getlist(name) Then you'll want a Form field that uses that widget, again expecting a list.
You'll need to think about validation there; you don't want to accept just any data. Then you'll need a filter to use the field:
But with that you'll be able to filter on many items, without erroring just because an ID doesn't exist. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given the following Model and Filter:
I need to filter Bar given multiple Foo foreign key ids.
For example
GET .../bar/?foo=1&foo=2&foo=3
From what I tested, the endpoint will only filter
foo=3
, I'm guessing always the last value.I've done some debug in the code, and there is a step somewhere that converts the list received in only one value.
I've tried adding a
'lookup_expr': 'in'
as an extra, but raises an exception saying'decimal.Decimal' object is not iterable
I also used the
ModelMultipleChoiceFilter
, but I don't want to return an error saying that some id doesn't exist.Basically, what I want is given the endpoint, I can filter Foreign Keys from their id, and if some value doesn't exist, ignores it. For example:
I'm using django-filter 21.1 and django-rest-framework, if it helps.
Beta Was this translation helpful? Give feedback.
All reactions