开发者

order_with_respect_to() Child relationship

开发者 https://www.devze.com 2022-12-10 22:51 出处:网络
I\'m trying to figure out how I can use: order_with_respect_to() to order via a Child relationship开发者_如何学Go

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

开发者_如何学Go
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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消