I'm constructing some Django filter queries dynamically, using this example:
kwargs = { 'deleted_datetime__isnull': True }
args = ( Q( title__icontains = 'Foo' ) | Q( title__icontains = 'Bar' ) )
entries = Entry.objects.filter( *args, **kwargs )
I'm just not sure how to construct the entry for args
. Say I have this array:
strings = ['Foo', 'Bar']
How do I get from there to:
args = ( Q( title__icontains = 'Foo' ) | Q( title__icontains = 'Bar' )
The closest I can get is:
for s in strings:
q_construct = Q( title__icontains = %s) % s
args.append(s)
But I don't know how to set up the |
condition.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…