Answer the question
In order to leave comments, you need to log in
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)
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