Here are my simple viewset and serializer classes:
class UserSerializer(ModelSerializer):
class Meta:
model = User
fields = ['id', 'email', 'first_name', 'last_name']
....
class UserViewSet(ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
Suppose I want to update only my user's first name. In that case, I should use PATCH
{"first_name": "New First Name"}
. But at the same time, it looks like that PUT
{"first_name": "New First Name"}
also works the same way, though it shouldn't, because it has to validate that all the fields are specified. At least I thought so. Am I wrong? And if I'm, then what is the difference between update
and partial_update
in Django Rest Framework and is there any reason to keep them both (since any additional method implies additional testing, so the latter question is a bit philosophical, because looks like people find this PUT/PATCH pair really confusing). By the way, I'm using djangorestframework==3.8.2
. Thank you.