Answers for "how to dinamically create the Q query in django"

0

how to dinamically create the Q query in django

tags = ['tag1', 'tag2', 'tag3']
q_objects = Q() # Create an empty Q object to start with
for t in tags:
    q_objects |= Q(tags__tag__contains=t) # 'or' the Q objects together

designs = Design.objects.filter(q_objects)
Posted by: Guest on April-20-2022

Python Answers by Framework

Browse Popular Code Answers by Language