我在使用以下反向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')
?
答案 0 :(得分:4)
由于您已将deliveries
指定为related_name
,请使用它:
OrderItem.objects.filter(deliveries__stage='Beginning')
答案 1 :(得分:2)
OrderItem.objects.filter(deliveries__stage='Beginning')