9
9
95506682020-08-21 14:17:42
Django
9550668, 2020-08-21 14:17:42

How to change the Serializer to adjust the search results?

Hello everyone once again.

There is the following code:

class BasicListAPIView(generics.ListAPIView, CustomMixin):
    serializer_class = BasicSerializer

    permission_classes = [IsAuthenticated]

    def get_queryset(self, *args, **kwargs):
        '''Search'''
        qs = List.objects.all()
        query_name = self.request.GET.get("name")

        if query_name is not None:
            qs = qs.filter(name__icontains=query_name).distinct()

        return qs


class BasicSerializer(serializers.ModelSerializer):
    class Meta:
        model = List
        fields = [
            'id',
            'name',
            'creator',
            'type',
            'description',
            'start_date',
            'end_date',
            'created_date',
            'is_active',
            'is_finished',
            'is_public',
        ]
        #read_only_fields = []


I need to edit the information in the 'creator' variable, obtained from the field'a of the List model, when issuing in JSON format.

Can you tell me which method in the serializer should be rewritten and how?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-22
@9550668

e.g. https://www.django-rest-framework.org/api-guide/se...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question