I am using the Ultimate Django course. I am up to part 2 Designing and Implementing a Shopping Cart API. It must be me because other people have done it, but I can’t see what is wrong. Thereare only three things to do according to Mosh: Create a View, Create a Serializer and Create a Route. Three simple steps I have done too many times now with the same result. When I Post to create the empty Cart I am greeted with
create()
must be implemented.
Request Method: | POST |
---|---|
Request URL: | http://127.0.0.1:8000/store/carts/ |
Django Version: | 4.2.5 |
Exception Type: | NotImplementedError |
Exception Value: | create() must be implemented. |
Which I thought was covered by
class CartViewSet(CreateModelMixin, GenericViewSet):
queryset = Cart.objects.all()
serializer_class = CartSerializer
What have I missed?
For completeness
URL
router.register(‘carts’, views.CartViewSet)
Serializer
class CartSerializer(serializers.Serializer):
id = serializers.UUIDField(read_only=True)
class Meta:
model = Cart
fields = ['id']