我的模特:
=IF(B2=1000,IF(COUNTIFS(A:A,A2,B:B,2000)>=1,A2,""),"")
相应的序列化器:
class Order(models.Model):
order_items = models.ManyToManyField('Product', through='OrderItem')
class OrderItem(models.Model):
order = models.ForeignKey('Order', null=True, on_delete=SET_NULL)
product = models.ForeignKey('Product', null=True, on_delete=SET_NULL)
class Product(models.Model):
title = models.CharField(max_length=1000)
当我执行GET请求时,得到以下结果。每个订单都包含一个数组class OrderItemSerializer(serializers.ModelSerializer):
class Meta:
model = OrderItem
fields = ('id', 'product', 'order', )
class OrderSerializer(serializers.ModelSerializer):
order_items = OrderItemSerializer(source='orderitem_set', many=True, read_only=True)
class Meta:
model = Order
fields = ('id', 'order_items')
,该数组与一个产品有关系,并且一个订单很好。
order_items
但是,我在创建新订单时遇到问题。我试图从我的 "results": [
{
"id": 1,
"order_items": [
{
"id": 1,
"product_variation": 1,
"order": 1
}
],
},
]
覆盖create方法,但是OrderSerializer
不在经过验证的数据中。什么是解决此问题的好方法?我在做什么错?