Django manytomanyfield field request error

My participants fields is Manytomanyfield. I will create new chat. What do should add participants in my request?

this User models.py:

class User(AbstractUser):
    phone = models.CharField(default=None, max_length=11, verbose_name='Telefon Numarası', blank=True)
    photo = models.ImageField(default=None, verbose_name='Profil Fotoğrafı', blank=True, null=True)
    company = models.ForeignKey(Company, null=True, blank=True, on_delete=models.CASCADE, verbose_name="Firma")

models.py:

class Chat(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE, verbose_name="Proje")
    name = models.CharField(max_length=255, verbose_name="Sohbet Adı")
    cover = models.ImageField(blank=True, verbose_name="Kapak Fotoğrafı")
    participants = models.ManyToManyField(User, verbose_name="Katılımcılar")


    def __str__(self):
        return self.name

serializers.py:


    class Meta:
        model = User
        fields = ['id']
class ChatSerializer(serializers.ModelSerializer):
    is_perm = serializers.SerializerMethodField('get_is_perm')
    participants = UserSerializer(many=True)

    class Meta:
        model = Chat
        fields = '__all__'

view.py:

class ChatList(generics.ListAPIView):
    serializer_class = ChatSerializer
    permission_classes = [permissions.IsAuthenticated]
    filter_backends = [filters.SearchFilter]
    search_fields = ['name']

    def get_queryset(self):
        queryset = Chat.objects.all()
        project = self.request.query_params.get('project', None)
        if project:
            queryset = queryset.filter(project__id=project)
        return queryset
    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)

my request: enter image description here

Back to Top