Answer the question
In order to leave comments, you need to log in
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 = []
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question