Skip to content

Instantly share code, notes, and snippets.

@sankalpjonn
Created June 27, 2021 02:21
Show Gist options
  • Save sankalpjonn/4de392eca0e0f7c923525dae03f1eacb to your computer and use it in GitHub Desktop.
Save sankalpjonn/4de392eca0e0f7c923525dae03f1eacb to your computer and use it in GitHub Desktop.
from rest_framework import generics
from .models import Record
from django.http import Http404
class RecordRetrieveView(generics.RetrieveAPIView):
serializer_class = RecordSerializer
def get_object(self):
try:
return Record.objects.get(id=self.request.query_params['id'])
except Record.DoesNotExist:
raise Http404()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment