如何在序列化程序`create()`方法中获取用户数据?

时间:2017-11-16 12:07:18

标签: python django django-rest-framework

如何在序列化程序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'对象没有属性'请求'

0 个答案:

没有答案