Re: Order model objects by foreign key "set" count

2010-01-11 Thread Scott Maher
Margie Roginski wrote: Say I have a Reader model that has a foreign key to a Book class Reader(models.Model): book = models.ForeignKey(Book) Now say I want to find all books and order them by the number of readers. Is that possible, ie something like this? Book.objects.all().order_by(reade

Re: Comparing ManyToMany fields

2009-12-27 Thread Scott Maher
akaariai wrote: > This is not the easiest query to perform using SQL. Something like the > following query might work, I have tested it only quickly. > > select t2.pizza_id > from (select pizza_id from pizza_toppings group by pizza_id >having count(*) = (select count(*) from pizza_toppings wher

Comparing ManyToMany fields

2009-12-27 Thread Scott Maher
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