Skip to content

Instantly share code, notes, and snippets.

@esirK
Created December 9, 2018 18:44
Show Gist options
  • Select an option

  • Save esirK/f41599e3023b292bd52f6af2defd4375 to your computer and use it in GitHub Desktop.

Select an option

Save esirK/f41599e3023b292bd52f6af2defd4375 to your computer and use it in GitHub Desktop.
class ArticleView(ListCreateAPIView):
queryset = Article.objects.all()
serializer_class = ArticleSerializer
def perform_create(self, serializer):
author = get_object_or_404(Author, id=self.request.data.get('author_id'))
return serializer.save(author=author)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment