Comment

Tom Leys

The correct solution is to use prefetch_related. Then django will do everything else you explain automatically.

https://docs.djangoproject.com/en/2.1/ref/models/querysets/#prefetch-related

Take your example code above "What's the problem?" then add queryset as below...

    class BlogpostViewSet(viewsets.ModelViewSet):
        queryset = Blogpost.objects.all().order_by('date').select_related('categories')
        serializer_class = serializers.BlogpostSerializer

I hope this helps.