Skip to content

ModelMultipleChoiceFilter with lookup_expr='in' #1433

Answered by rpkilby
emilt27 asked this question in Q&A
Discussion options

You must be logged in to vote

#1054 changed this. I don't think lookup_expr was previously used, and by default, Q objects are OR'ed together, so the result looks like it was performing an in lookup. e.g.,

MyModel.objects.filter(Q(field='value1') | Q(field='value2'))

The PR changed this so lookup expressions are accounted for, so you could queries like

MyModel.objects.filter(Q(field__contains='value1') | Q(field__contains='value2'))

However, in your case, the in lookup expects a list of values, which is why you get an error. It should be safe to drop lookup_expr='in'

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by carltongibson
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
Converted from issue

This discussion was converted from issue #1106 on August 26, 2021 16:04.