order_with_respect_to() 子关系
我正在想办法如何使用:
order_with_respect_to()来根据子关系进行排序。
class Product(models.Model):
name = models.CharField(max_length=100)
class Affiliate(models.Model):
product = models.ForeignKey(Product)
clicks = models.IntegerField(default=0)
我希望能够按照联盟点击的数量来显示产品。
我看到的所有例子都是通过父级属性来排序子关系。
也许还有其他更好的方法来实现这个目标,而不是使用order_with_respect_to()。
谢谢,
Bryan
2 个回答
0
请查看 order_with_respect_to
的文档,更新内容可以在这里找到,这些内容是在这个问题发布后更新的。
1
看看聚合功能(http://docs.djangoproject.com/en/dev/topics/db/aggregation/)。我觉得你可以用它们来帮助解决这个问题。