I'm trying to figure out how I can use: order_with_respect_to() to order via a Child relationship
开发者_如何学Goclass 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
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.
See order_with_respect_to
documentation here, updated since this question was posted.
精彩评论