' NoneType'对象没有属性'属性'在django oscar中创建新的目录产品

时间:2016-01-28 11:03:01

标签: django django-rest-framework django-oscar

在视图中,我正在尝试基于产品序列化器创建基于django oscar产品型号的新产品。我总是会遇到此错误' NoneType'对象没有属性'以下是我的代码

Views.py

    from serializers import CategorySerializer, ProductSerializer, ProductClassSerializer
    from oscar.apps.catalogue.models import Product, Category, ProductClass


class ProductViewSet(viewsets.ModelViewSet):
    """
    A viewset for viewing and editing product instances.
    """
    serializer_class = ProductSerializer
    queryset = Product.objects.all()

    # create a product
    def create(self, request, format=None):
        data = json.loads(request.body)
        serializer = ProductSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Serializers.py

class ProductSerializer(serializers.ModelSerializer):


    class Meta:
        model = Product

1 个答案:

答案 0 :(得分:1)

您可能在代码中的其他位置尝试访问Select Key1, Value1 into #TempTable FROM OPENXML(@handle, '//ValueSet/Values', 1) WITH ( key1 VARCHAR(MAX), value1 varchar(100) ) ,其中product.attributes等于product