1👍
✅
Assign the perform_create
function as perform_update
as well:
class ArticleView(viewsets.ModelViewSet):
queryset = Article.objects.all()
serializer_class = ArticleSerializer
def perform_create(self, serializer):
author = get_object_or_404(Author, id=self.request.data['author']['id'])
return serializer.save(author=author)
perform_update = perform_create
Source:stackexchange.com