I have a problem passing arguments through a list to Django filter. Here my code:
args = [ "Q( title__icontains = 'Foo' ) | Q( author__icontains = 'Foo' )", "Q( title__icontains = 'Bar' ) | Q( author__icontains = 'Bar' )" ]
entries = Book.objects.filter( *args )
but filter
returns this error:
ValueError: too many values to unpack,
答案 0 :(得分:3)
Your args are strings, but they must be Q
objects. Remove the quotes around your Q
object definitions.
答案 1 :(得分:2)
Remove all " and you get it right.
args = [ Q( title__icontains = 'Foo' ) | Q( author__icontains = 'Foo' ), Q( title__icontains = 'Bar' ) | Q( author__icontains = 'Bar' )]
entries = Book.objects.filter( *args )