def post(request): serializer = CreateSplitSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) try: if Split.objects.filter( original_log=serializer.validated_data['original_log'], test_size=serializer.validated_data['test_size'], splitting_method=serializer.validated_data['splitting_method'] ).exists(): return Response(Split.objects.filter( original_log=serializer.validated_data['original_log'], test_size=serializer.validated_data['test_size'], splitting_method=serializer.validated_data['splitting_method'] )[0].to_dict(), status=status.HTTP_200_OK) # TODO: Use better code, like 304 else: # Other serializer for data split = serializer.save() except: # Other serializer for data split = serializer.save() result = SplitSerializer(split) return Response(result.data, status=status.HTTP_201_CREATED)
class ModelSerializer(serializers.ModelSerializer): split = SplitSerializer(many=False, read_only=True) type = serializers.CharField() config = serializers.JSONField() class Meta: model = PredModels fields = ('id', 'split', 'type', 'config')
def post(request): serializer = CreateSplitSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) # Other serializer for data item = serializer.save() result = SplitSerializer(item) return Response(result.data, status=status.HTTP_201_CREATED)
def upload_multiple(request): print('Double upload request received.') test_log = create_log(request.FILES['testSet'], request.FILES['testSet'].name) train_log = create_log(request.FILES['trainingSet'], request.FILES['trainingSet'].name) item = Split.objects.create( type='double', train_log=train_log, test_log=test_log) serializer = SplitSerializer(item) return Response(serializer.data, status=status.HTTP_201_CREATED)