def post(self, request, machine, field, value, format=None): request.data['parent'] = machine.serial serializedCharacteristics=CharacteristicsSerializer(data=request.data) if serializedCharacteristics.is_valid(): serializedCharacteristics.save() return Response(serializedCharacteristics.data, status = status.HTTP_201_CREATED) return Response(serializedCharacteristics.errors, status = status.HTTP_400_BAD_REQUEST)
def post(self, request, machine, field, value, format=None): request.data['parent'] = machine.serial serializedCharacteristics = CharacteristicsSerializer( data=request.data) if serializedCharacteristics.is_valid(): serializedCharacteristics.save() return Response(serializedCharacteristics.data, status=status.HTTP_201_CREATED) return Response(serializedCharacteristics.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, machine, field, value, format=None): characteristics = machine.characteristics.get(characteristicType__iexact=field) if not value: serializedCharacteristics = CharacteristicsSerializer(characteristics, data=request.data) if serializedCharacteristics.is_valid(): serializedCharacteristics.save() else: characteristics.value = request.data.get(value) characteristics.save() serializedCharacteristics = CharacteristicsSerializer(characteristics) return Response(serializedCharacteristics.data) return Response(serializedCharacteristics.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, machine, field, value, format=None): if field.lower() == 'characteristics': characteristics = machine.characteristics.all() serializedCharacteristics = CharacteristicsSerializer( characteristics, many=True) return Response(serializedCharacteristics.data) else: characteristics = machine.characteristics.get( characteristicType__iexact=field) serializedCharacteristics = CharacteristicsSerializer( characteristics) if value: return Response(serializedCharacteristics.data.get(value)) else: return Response(serializedCharacteristics.data)
def put(self, request, machine, field, value, format=None): characteristics = machine.characteristics.get( characteristicType__iexact=field) if not value: serializedCharacteristics = CharacteristicsSerializer( characteristics, data=request.data) if serializedCharacteristics.is_valid(): serializedCharacteristics.save() else: characteristics.value = request.data.get(value) characteristics.save() serializedCharacteristics = CharacteristicsSerializer( characteristics) return Response(serializedCharacteristics.data) return Response(serializedCharacteristics.errors, status=status.HTTP_400_BAD_REQUEST)