I have a question with adding Count Objects in Django Rest Framework Viewset: This is my curren API:
[
{
"id": 1,
"created": "2017-12-25T10:29:13.055000Z"
},
{
"id": 2,
"created": "2017-12-25T10:29:13.055000Z"
}
]
Now I want to add Count Objects outside this API and collect them in results array like this:
{
"count_objects": 2,
"results": [
{
"id": 1,
"created": "2017-12-25T10:29:13.055000Z"
},
{
"id": 2,
"created": "2017-12-25T10:29:13.055000Z"
}
]
}
How can I do this in the right way? Now my viewset.py is:
class NotificationAPIView(ReadOnlyModelViewSet):
queryset = Notification.objects.all()
serializer_class = NotificationSerializer
def get_queryset(self, *args, **kwargs):
queryset_list = Notification.objects.filter(to_user=self.request.user)
return queryset_list