Horje
github/hacksofteare Code Example
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)
Source: github.com
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)
Source: github.com
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)
Source: github.com




Shell

Related
ubuntu change to thunar Code Example ubuntu change to thunar Code Example
how to open current terminal directory in file explorer Code Example how to open current terminal directory in file explorer Code Example
How to find a process running on a linux machine from terminal Code Example How to find a process running on a linux machine from terminal Code Example
qemu convert qcow2 to vmdk Code Example qemu convert qcow2 to vmdk Code Example
how to define a command in bashrc Code Example how to define a command in bashrc Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10