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

    example.com/api/pk/ where pk is the object id.

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?

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to