Skip to content

Latest commit

 

History

History
87 lines (66 loc) · 2.13 KB

checklist.md

File metadata and controls

87 lines (66 loc) · 2.13 KB

Check Your Code Against the Following Points

Code Style

  1. Don't forget define the related_name for ManyToManyField.

  2. Don't forget return Response with errors if serializer is not valid:

Good example:

class GenreList(APIView):
    def post(self, request):
        serializer = GenreSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
    
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Another good example:

class GenreList(APIView):
    def post(self, request):
        serializer = GenreSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)

Bad example:

class GenreList(APIView):
    def post(self, request):
        serializer = GenreSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)

Another bad example:

class GenreList(APIView):
    def post(self, request):
        serializer = GenreSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
    
        return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST)
  1. Group imports using () if needed.

Good example:

from django.contrib.auth.mixins import (
    LoginRequiredMixin, 
    UserPassesTestMixin, 
    PermissionRequiredMixin,
)

Bad example:

from django.contrib.auth.mixins import LoginRequiredMixin, \
    UserPassesTestMixin, PermissionRequiredMixin

Another bad example:

from django.contrib.auth.mixins import (
    LoginRequiredMixin, 
    UserPassesTestMixin, PermissionRequiredMixin,
)

Clean Code

Add comments, prints, and functions to check your solution when you write your code. Don't forget to delete them when you are ready to commit and push your code.