Django Rest api Update View form can't update single attribute

I have created an Employee CRUD in Django REST using generic views. when update view page is loaded I couldn't find the current values in the fields. so I can't update a single value. when i update a single value it shows other fields must be required.

I need to update a single value. eg: Phonenumber How can i do that?

class EmpUpdateView(UpdateAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmpModelSerializer
    lookup_field = 'id'

[enter image description here](https://i.stack.imgur.com/7Slum.png)

enter image description here

Use a patch method as it uses partial_update

class EmpUpdateView(UpdateAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmpModelSerializer
    lookup_field = 'id'

    def patch(self, request, *args, **kwargs):
        # Add your business logic if any
        return self.partial_update(request, *args, **kwargs)

Note: Partial update just adds kwargs['partial'] = True and perform update operation.

DRF Source code:

    def partial_update(self, request, *args, **kwargs):
        kwargs['partial'] = True
        return self.update(request, *args, **kwargs)
Back to Top