Created
January 5, 2015 01:59
-
-
Save ionatan-israel/d331ec0ae8b49af8db6f to your computer and use it in GitHub Desktop.
Snippet Django para buscar diferentes palabras en un mismo campo. Es una pena que no exista 'field__contains__in'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Q | |
lista = ['str1', 'str2', 'str3'] | |
q_objects = Q() | |
for x in lista: | |
q_objects |= Q(title__contains=x) | |
queryset = queryset.filter(q_objects) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment