我有以下型号:
class Invoice(models.Model):
invoice_number = models.CharField(max_length=100)
order_items = models.ManyToManyField(OrderItem)
如何获取不在发票中的所有order_items
?
就像是:
OrderItem.objects.exclude(id__in=invoice) # pseudocode
答案 0 :(得分:1)
你可以做到
ordered_items_not_in_invoice = OrderItem.objects.filter(invoice__isnull=True)