Skip to content

Instantly share code, notes, and snippets.

@hemanth-sp
Created February 3, 2021 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemanth-sp/8c0bc929ae715c03e4f7f73d303b913d to your computer and use it in GitHub Desktop.
Save hemanth-sp/8c0bc929ae715c03e4f7f73d303b913d to your computer and use it in GitHub Desktop.
Generic class-based view curd
from rest_framework.views import APIView
from curd.serializers import StudentSerializers
from curd.models import Student
from rest_framework import status, permissions, generics
from rest_framework.response import Response
from django.shortcuts import get_object_or_404
class StudentCurd(generics.ListCreateAPIView):
queryset = Student.objects.all()
serializer_class = StudentSerializers
permission_classes = [permissions.AllowAny]
class StudentCurdd(generics.RetrieveUpdateDestroyAPIView):
queryset = Student.objects.all()
serializer_class = StudentSerializers
permission_classes = [permissions.AllowAny]
urlpatterns = [
path('students', StudentCurd.as_view(), name="students_list_or_create"),
path('students/<int:pk>/', StudentCurdd.as_view(), name="students_get_or_update"),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment