I want to update a field in my model whenever an object link is called through the api. I'm using Django Rest Framework to handle the creation of api.
The link to a single object is
In the model viewset, I wrote a partial update method to handle the addition of 1 to the field whenever the object is called upon.
class RocNationViewSet(viewsets.ModelViewSet):
queryset=RocNation.objects.filter(is_active=True).order_by('-pub_date')
serializer_class=RocNationSerializer
filter_backends = (DjangoFilterBackend,)
def partial_update(self, request, pk=None):
serializer=RocNationSerializer(rocnation, roc_views=F('roc_views')+1, partial=True)
serializer.save()
return Response(serializer.data)
The method is not carrying out the operation. The field in the model is not updated. What am I missing?