Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

github/hacksofteare

class CourseListApi(SomeAuthenticationMixin, APIView):
    class OutputSerializer(serializers.ModelSerializer):
        class Meta:
            model = Course
            fields = ('id', 'name', 'start_date', 'end_date')

    def get(self, request):
        courses = get_courses()

        serializer = self.OutputSerializer(courses, many=True)

        return Response(serializer.data)
Comment

github/hacksofteare

class CourseDetailApi(SomeAuthenticationMixin, APIView):
    class OutputSerializer(serializers.ModelSerializer):
        class Meta:
            model = Course
            fields = ('id', 'name', 'start_date', 'end_date')

    def get(self, request, course_id):
        course = get_course(id=course_id)

        serializer = self.OutputSerializer(course)

        return Response(serializer.data)
Comment

github/hacksofteare

class CourseCreateApi(SomeAuthenticationMixin, APIView):
    class InputSerializer(serializers.Serializer):
        name = serializers.CharField()
        start_date = serializers.DateField()
        end_date = serializers.DateField()

    def post(self, request):
        serializer = self.InputSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        create_course(**serializer.validated_data)

        return Response(status=status.HTTP_201_CREATED)
Comment

PREVIOUS NEXT
Code Example
Python :: drop duplicates pandas considering lowercase 
Python :: python set table widget header 
Python :: Return the indices of the bins 
Python :: dream manhunt 
Python :: dynamic frame latest record 
Python :: sort dataset date wise in matplotlib 
Python :: How to open hyperlink with target=“_blank” in PyQt5 
Python :: python sort list of tuples lexicographically 
Python :: use colabs gpu locally 
Python :: python set class variable 
Python :: Blender Python perspective camaera 
Python :: not to display column tree odoo 8 
Python :: does the queen brush her teeth 
Python :: tf.slice 
Python :: python cows and bulls 
Python :: Get the first item from an iterable that matches a condition 
Python :: increment numper in python 
Python :: py2-pip (no such package) required by world py2-pip 
Python :: python dt error only use with datetimelike values 
Python :: download image from url python 
Python :: jugendwort 2019 
Python :: image.show pillow mac os 
Python :: what hormone causes the feeling of love 
Python :: print convert hex as string ascii 
Python :: chrome crushs in selenium 
Python :: Using rstrip() method to remove the newline character from a string 
Python :: print 1 side of a dictionary python 
Python :: what is fourier transform in python 
Python :: select series of columns 
Python :: long press selenium python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =