def put(self, request, pk, format=None): skill = self.get_object(pk) serializer = SkillSerializer(skill, 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)
def post(self, request, character_pk=None): data = {**request.data, "character": character_pk} skill_serializer = SkillSerializer(data=data, context={'request': request}) if skill_serializer.is_valid(): skill_serializer.save() return Response(skill_serializer.data, status=status.HTTP_201_CREATED) return Response(skill_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def patch(self, request, character_pk=None, skill_pk=None, format=None): skill_instance = get_skill_or_none(character_pk, skill_pk) if skill_instance: skill_serializer = SkillSerializer(instance=skill_instance, data=request.data, context={'request': request}, partial=True) if skill_serializer.is_valid(): skill_serializer.save() return Response(skill_serializer.data, status=status.HTTP_200_OK) return Response(skill_serializer.errors, status=status.HTTP_400_BAD_REQUEST) return SKILL_DOES_NOT_EXIST_RESPONSE
def get(self, request, character_pk=None): return Response(SkillSerializer( Skill.objects.filter(character__id=character_pk), many=True, context={ 'request': request }).data, status=status.HTTP_200_OK)
def get(self, request, character_pk=None, skill_pk=None, format=None): skill_instance = get_skill_or_none(character_pk, skill_pk) if skill_instance: return Response(SkillSerializer(instance=skill_instance, many=False, context={ 'request': request }).data, status=status.HTTP_200_OK) return SKILL_DOES_NOT_EXIST_RESPONSE
def skillDetail(request, pk): queryset = Skill.objects.get(id=pk) serializer = SkillSerializer(queryset, many=False) return Response(serializer.data)
def skillList(request): queryset = Skill.objects.all() serializer = SkillSerializer(queryset, many=True) return Response(serializer.data)
def get(self, request, pk, format=None): skill = self.get_object(pk) serializer = SkillSerializer(skill) return Response(serializer.data)