I have the following serilizers
class MarcaSerializer(serializers.ModelSerializer):
class Meta:
model = Marca
fields = ("codigo",)
class AutoSerializer(WritableNestedModelSerializer):
marca = MarcaSerializer()
class Meta:
model = Auto
fields = ("nombre", 'marca')
When I use the api, through django-debug-tolbar, I can verify that it performs a consulata to the BD, where it calls all the fields of the models, and not necessarily to those that it specifies in the fields of each serializer , as I do so that it only extracts from the BD the fields specified in the fields ViewSetModel
class MarcaViewSet(viewsets.ModelViewSet):
queryset = Auto.objects.all().select_related("marca")
serializer_class = AutoSerializer
def list(self, request, *args, **kwargs):
queryset = self.queryset
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)