S
S
s1vemod2021-06-08 18:29:16
Django
s1vemod, 2021-06-08 18:29:16

How to update ManyToManyField field?

Good evening. Tell me how can I update the tasks = models.ManyToManyField(Task) field in the User model . I get PATCH in GenericViewSet , mixins.UpdateModelMixin , with data - task_id . How can I update only the tasks field in the User model ? Thank you in advance. Stuck on this:




@action(detail=False, methods=['PATCH'], permission_classes=[IsAuthenticated])
    def task_in_user_update():
        task_id = int(request.data.get('task_id'))
        answer = str(request.data.get('answer'))
        user_id = int(request.user.id)

        if not task_id or not answer:
            return Response(status=status.HTTP_204_NO_CONTENT)


I did not see in the documentation how this is implemented.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question