Skip to content

Instantly share code, notes, and snippets.

@andretw
Created April 11, 2014 08:59
Show Gist options
  • Save andretw/10451593 to your computer and use it in GitHub Desktop.
Save andretw/10451593 to your computer and use it in GitHub Desktop.
from django.db.models import Q
tag_list = ['a', 'b', 'c']
q_objects = Q()
for t in tag_list:
# Use |= for 'or' &= for 'and'
q_objects &= Q(blogpost__keyword=t)
blog_posts = blog_posts.filter(q_objects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment