如何在序列化程序create()
方法中获取用户数据?
我试图让用户数据使用self.request,但失败了:
class OrderCreateSerializer(ModelSerializer):
class Meta:
model = Order
fields = (
"product_describe",
"billing_type",
"buytime",
"count",
"paytype",
)
def create(self, validated_data):
print(self.request.user.username)
validated_data["order_num"] = generateOrderNum()
return Order.objects.save()
' OrderCreateSerializer'对象没有属性'请求'