Skip to content
thesarfo

Note

Building the Profile API

A CustomerViewSet built from CreateModelMixin, RetrieveModelMixin, and UpdateModelMixin since Djoser doesn't cover profile endpoints.

views 0

Note that, the endpoints that Djoser provides are all for managing users and managing authentication. It doesnt include profile endpoints, so we have to build it ourselves. We will build this api in the store app

First create a customer serializer

class CustomerSerializer(serializers.ModelSerializer):
user_id = serializers.IntegerField()
class Meta:
model = Customer
fields = ['id', 'user_id', 'phone', 'birth_date', 'membership']

And then create a viewset

class CustomerViewSet(CreateModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericViewSet):
'''we use mixins that represent only the methods we want to perform on our customer'''
queryset = Customer.objects.all()
serializer_class = CustomerSerializer

then register a route

router.register('customers', views.CustomerViewSet)