@staticmethod
PYL-R0201103 return Response(serialized_source.data, status=status.HTTP_202_ACCEPTED)
104 return Response(serialized_source.errors, status=status.HTTP_400_BAD_REQUEST)
105
106 def delete(self, request, project_id, pk):107 try:
108 required_source = Source.objects.get(pk=pk)
109 except Source.DoesNotExist:
84class SourceDetailedView(APIView):
85 """Retrieve, Update and Delete on `Source` model"""
86
87 def get_object(self, pk): 88 try:
89 return Source.objects.get(pk=pk)
90 except Source.DoesNotExist:
72 serialized_sources = SourceSerializer(all_source, many=True)
73 return Response(serialized_sources.data, status=status.HTTP_200_OK)
74
75 def post(self, request, project_id): 76 request.data["project"] = project_id
77 serialized_source = SourceSerializer(data=request.data)
78 if serialized_source.is_valid():
55class SourceView(APIView):
56 """Create amd List on`Source` model"""
57
58 def get_project(self, project_id): 59 """Returns a `Project` model associated with the Source"""
60 try:
61 return Project.objects.get(pk=project_id)
46 return Response(serialized_project.data, status=status.HTTP_202_ACCEPTED)
47 return Response(serialized_project.errors, status=status.HTTP_400_BAD_REQUEST)
48
49 def delete(self, request, pk): 50 required_project = Project.objects.get(pk=pk)
51 required_project.delete()
52 return Response(status=status.HTTP_204_NO_CONTENT)
The method doesn't use its bound instance. Decorate this method with @staticmethod
decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.