On Mon, 2009-03-02 at 13:59 -0800, natx...@gmail.com wrote:
> I'm trying to make a complex dynamic filter. The first thing I've done
> is get dynamically a list of list of titles, something like this:
> 
> [[<Titulo: Diplomatura, Educación Infantil>, <Titulo: Diplomatura,
> Educación>], [<Titulo: Idiomas, EGA>]]
> 
> and a way to add/remove list of titles to/from the general list (let's
> call it big list).
> 
> Is there a way to filter a list of Persons that have Titles (m2m)
> using AND in the big list and OR inside each little list?
> In the example something like a person that have:
> 
> OR(<Titulo: Diplomatura, Educación Infantil>, <Titulo: Diplomatura,
> Educación) AND(<Titulo: Idiomas, EGA>)

The key thing here are Q() objects. See [1] for the documentation. In
fact, under the covers, all filter() calls become Q() objects, so they
really are key.

You can combine Q's using & and | however you like. So wrapping each
item as a Q(title=some_title) and then putting them together, using a
loop or reduce() will do what you want.

[1]
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to