我有以下两个模型:
class OrderItem(models.Model):
order = models.ForeignKey(Order, related_name='items')
title = models.ForeignKey(Title, related_name='order_items')
class OrderNotes(models.Model):
order_item = models.ForeignKey('OrderItem', blank=True, null=True)
timestamp = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
我将如何OrderItem
按最近OrderNote
的活动对 s 进行排序?
在伪代码中:
OrderItem.objects.order_by('ordernotes_set.order_by('is_active', '-timestamp'))
?