我有一个PaymentOrRefund模型。显然,负数是退款。每笔付款/退款都是根据一张或多张发票登记的。
class PaymentOrRefund(models.Model):
amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
invoices = models.ManyToManyField(Invoice, blank=True, related_name="payments")
视图中的变量是:refund和payment_to_refund
付款时,客户端选择付款所针对的发票。退款时,客户端选择退款的付款,但退款的发票在服务器端设置。需要从payment_to_refund分配这些发票。
这不起作用:
refund.invoices = payment_to_refund.invoices
也不是这样:
refund.invoices.all() = payment_to_refund.invoices.all()
答案 0 :(得分:0)
问题解决了:
refund.invoices = payment_to_refund.invoices.all()