Skip to content

Instantly share code, notes, and snippets.

@esirK
Created November 20, 2018 11:26
Show Gist options
  • Select an option

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

Select an option

Save esirK/ba8b21e74e21185f298d5eaebb3686a8 to your computer and use it in GitHub Desktop.
class ArticleView(ListModelMixin, CreateModelMixin, GenericAPIView):
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)
def get(self, request, *args, **kwargs):
return self.list(request, *args, *kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
@mrbardia72

Copy link
Copy Markdown

o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment