[Django]-Django: OR queries with dynamic field names

7👍

Use ** dictionary-to-kw-args expansion:

q = Q()
for field in fields:
    q = q | Q(**{field: "value"})

(as Q() yield a Q which “does nothing”, as far as I can tell)

Leave a comment