You can also try this:
or_query = Q()
if places:
or_query = or_query | Q(persplace__icontains=places)
if names:
or_query = or_query | Q(persname__icontains=names)
results = Person.objects.filter(or_query)
--~--~-~--~~~---~--~~
You received this
Dear Christian,
Thanks a lot, this is exactly what I needed and it works like a charm!
For the moment, I am using a list, as you suggested, since I am not
using the keys of the dictionary. And I had to make a slight change,
since what I needed was an AND operator, not or, so I ended up with:
chris wrote:
> Dear django users,
>
> Being rather new to django, I can't wrap my head around the
> following:
> I am trying to execute a query from a search form. The search form
> has three fields, Names, Dates and Places. I want to AND the queries,
> so that if Names and Places are filled in
3 matches
Mail list logo