If write my own implementation of a
ViewSet, and I want to return some objects, it's pretty simple:
class MyViewSet(ViewSet): def my_method(self, request): objects = MyModel.objects.all() return Response( MyModelSerializer(objects, many=True).data )
But let's say that I want to include the actual instance of another linked resource by a
ForeignKey, instead of just an ID. For example:
class MyModel(Model): author = ForeignKey(MyOtherModel) ...
Is there a way to do something like this?
... return Response( MyModelSerializer(objects, many=True, include='author').data )