Please help solve the problem. I need to organize a search by chat name. But the chat name is created when the object is serialized.
name = serializers.SerializerMethodField('get_chat_name') SearchFilter works with a queryset, but the queryset does not have this field. Because this field is added at the time of serialization.
class ChatList(generics.ListAPIView): permission_classes = (permissions.IsAuthenticated,) serializer_class = ChatSerializers filter_backends = (SearchFilter,) search_fields = ('name',) def get_queryset(self): user = self.request.user return Chat.objects.filter(chatusers__user=user) class ChatSerializers(serializers.ModelSerializer): name = serializers.SerializerMethodField('get_chat_name') def get_chat_name(self, chat): if chat.type == 0: queryset = ChatUsers.objects.exclude(user = self.context['request'].user).get(chat=chat.pk) user_name = queryset.user.get_full_name() if user_name: return user_name else: return queryset.user.username if chat.type == 1: return chat.name` We need to find an adequate solution to this problem. Any ideas? I would be grateful for any help.