Skip to content
Advertisement

add a single data to serializer in django

enter image description here

I’m writing an API where the user’s followers are listed.I also want to send the total number of followers in this API.But the totalFollower field keeps repeating.I only want it sent once. Like that:

JavaScript

MY serializer

JavaScript

Advertisement

Answer

You have a couple of options:

Use a DRF paginator on your view, which will give a count in the response body:

JavaScript

Alternatively if you are using a viewset or something similar like ListAPIView you can add the specific data into the response for the list function:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement