Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Class based Django rest framework

from snippets.models import Snippet
from snippets.serializers import SnippetSerializer
from rest_framework import mixins
from rest_framework import generics

class SnippetList(mixins.ListModelMixin,
                  mixins.CreateModelMixin,
                  generics.GenericAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer

    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)
      
class SnippetDetail(mixins.RetrieveModelMixin,
                    mixins.UpdateModelMixin,
                    mixins.DestroyModelMixin,
                    generics.GenericAPIView):
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer

    def get(self, request, *args, **kwargs):
        return self.retrieve(request, *args, **kwargs)

    def put(self, request, *args, **kwargs):
        return self.update(request, *args, **kwargs)

    def delete(self, request, *args, **kwargs):
        return self.destroy(request, *args, **kwargs      
Comment

PREVIOUS NEXT
Code Example
Python :: immutabledict working 
Python :: print backward number from input 
Python :: django not configured pylint error fix 
Python :: flask-sqlalchemy inheritance 
Python :: how to strip characters in python 
Python :: how to clear formatting in python 
Python :: Python | Program to print duplicates from a list of integers 
Python :: awesome python 
Python :: how to print tic tac toe border on terminal in python 
Python :: self argument in python 
Python :: make max function returning more than one value python 
Python :: python how to tell if class is initialized 
Python :: Strings Formatting Old Way 
Python :: stackoverflow Django ForeignKey 
Python :: python os module using stat 
Python :: Python Program to Display Powers of 2 Using Anonymous Function 
Python :: how to download a website using python 
Python :: spark sparsevector to list 
Python :: difference between = and is not python 
Python :: what is require_self 
Python :: voting classifier grid search 
Python :: how to write a program that interacts with the terminal 
Python :: tkinter lottery app 
Python :: plt.plot(x, softmax(scores).T, linewidth=2) 
Python :: promedio en pandas 
Python :: How to import modules in Python? 
Python :: Python match.span() 
Python :: To do floor division and get an integer result (discarding any fractional result) 
Python :: can you use pop on a string 
Python :: Python RegEx re.compile() Set class [s,.] will match any whitespace character ‘,’ or ‘.’ 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =