Filter Django QuerySet to include the results from the given list only -


i need books title contain 'parts' variable-length list.

like (not working):

title_list = ['tree', 'sun'] books = books.objects.filter(title__icontains=title_list) 

or in sql (working):

select * `books` title '%tree%' , title '%sun%'; 

how can this?

this appears work:

from django.db.models import q  title_list = ['tree', 'sun']  books.objects.filter(reduce(lambda a, b: & b, [q(title__icontains=title) title in title_list]) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -