From f358acca058ab55e51067dad2d9cfb02e441acfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 27 Feb 2020 12:10:26 +0100 Subject: [PATCH] Fix payment creation --- uncloud/uncloud_pay/serializers.py | 4 ++-- uncloud/uncloud_pay/views.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index e11544b..024fe3f 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -4,9 +4,9 @@ from .models import Bill, Payment class BillSerializer(serializers.ModelSerializer): class Meta: model = Bill - fields = ['user', 'amount'] + fields = ['owner', 'amount'] class PaymentSerializer(serializers.ModelSerializer): class Meta: model = Payment - fields = ['user', 'amount', 'source', 'timestamp'] + fields = ['owner', 'amount', 'source', 'timestamp'] diff --git a/uncloud/uncloud_pay/views.py b/uncloud/uncloud_pay/views.py index 8fc02ea..8f37814 100644 --- a/uncloud/uncloud_pay/views.py +++ b/uncloud/uncloud_pay/views.py @@ -1,8 +1,10 @@ from django.shortcuts import render -from rest_framework import viewsets, permissions +from rest_framework import viewsets, permissions, status +from rest_framework.response import Response from .models import Bill, Payment from .serializers import BillSerializer, PaymentSerializer +from datetime import datetime # to be implemented @@ -35,12 +37,12 @@ class PaymentViewSet(viewsets.ModelViewSet): http_method_names = ['get', 'post'] def get_queryset(self): - return Payment.objects.filter(user=self.request.user) + return Payment.objects.filter(owner=self.request.user) def create(self, request): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) - serializer.save(user=request.user,timestamp=datetime.now()) + serializer.save(owner=request.user,timestamp=datetime.now()) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)