Skip to content
Advertisement

Django rest_framework : count objects and return value to serializer

i need to count all supporters in model and return value to serializer

models.py

JavaScript

serializers.py

JavaScript

views.py

JavaScript

Advertisement

Answer

About your serializer file, beware of indentation, here is an example. As for counting objects, i believe you are looking for something like this:

JavaScript

As specified in the queryset documentation. It is also possible to use the asynchronous version since Django version 4.1:

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