Hi

a pizza has a one to many relationship with its topping. in a list of pizzas 
there could be some that have the same topping, like thick, thin etc.

the query would look like

select pizza from pizzas where topping = xyz

cheers


michael



----- Original Message ----
From: Scott Maher <sc...@thereceptor.net>
To: django-users@googlegroups.com
Sent: Sun, December 27, 2009 9:32:22 AM
Subject: Comparing ManyToMany fields

Is it possible to filter by the ManyToMany fields?

Suppose I have a Pizza model and a Topping model. Topping has a 
ManyToManyField pointing to Pizza. I now have an instance of a Pizza 
called mypizza.

I would like to now search for all Pizzas with the EXACT same Toppings 
as mypizza. Intuitively it would like something like this:

Pizza.objects.filter(toppings=mypizza.toppings_set)

This, naturally, does not work. Any ideas? I'm happy to do some fancy 
black magic with the models to make it work, or do a custom SQL clause. 
I just don't know enough SQL to do that.

I'm also interested in reasonably alternative ways to model my data if I 
have a potentially very large set of Pizzas however a limited (although 
fairly lengthy, 20+) list of toppings that might change periodically.

Thanks!

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.


      

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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