0

我在使用以下反向 FK 查找时遇到问题:

class OrderItem(models.Model):
    order = models.ForeignKey(Order, related_name='items')
    title = models.ForeignKey(Title, related_name='order_items')

class OrderItemDelivery(models.Model):
    order_item = models.ForeignKey(OrderItem, related_name='deliveries')
    stage = models.CharField(max_length=20)

我将如何执行以下操作:OrderItem.objects.filter(order_item_delivery__stage='Beginning')

4

2 回答 2

4

正如您指定deliveriesrelated_name,使用它:

OrderItem.objects.filter(deliveries__stage='Beginning')
于 2013-01-15T23:36:35.910 回答
2
 OrderItem.objects.filter(deliveries__stage='Beginning')
于 2013-01-15T23:36:15.607 回答