[Answered ]-How to create view and serializer to add to many to many field in DRF

1👍

You can use the method perfom_create.

for example in your CreateView just after the serializer add this :

def perform_create(self, serializer):
    dish = Dish.objects.get(pk=self.kwargs['pk']) 
    serializer.save(dish=dish, author=self.request.user)

From the documentation :

For instance, you might set an attribute on the object based on the
request user, or based on a URL keyword argument.

Leave a comment