Exemplo n.º 1
0
    def get_queryset(self):
        queryset = self.model.objects
        serializer = self.empty_serializer

        for field in serializers.get_related_fields(serializer):
            queryset = queryset.select_related(field.source)

        for field in serializers.get_many_related_fields(serializer):
            queryset = queryset.prefetch_related(field.source)

        return queryset
    def test_returns_correct_many_related_fields(self):
        serializer = BookSerializer()
        fields = serializers.get_many_related_fields(serializer)

        self.assertEqual(fields[0].field_name, 'chapters')