tags:

views:

77

answers:

1

I'm trying to figure out how I can use: order_with_respect_to() to order via a Child relationship

class Product(models.Model):
   name = models.CharField(max_length=100)

class Affiliate(models.Model):
   product = models.ForeignKey(Product)
   clicks = models.IntegerField(default=0)

I want to be able to display the Products in order of the the number of affiliate clicks.

All the examples I have seen are ordering Child relationships via Parent attributes.

Perhaps there is a better way of doing this other than order_with_respect_to()

thanks, Bryan

+1  A: 

Take a look at aggregates (http://docs.djangoproject.com/en/dev/topics/db/aggregation/). I think you can use them to help you with this problem.

Rishabh Manocha