Introduce custom ProductViewSet preventing customer from updating

products
This commit is contained in:
fnux 2020-02-28 14:57:45 +01:00
commit b3bbfafa04
3 changed files with 19 additions and 3 deletions

View file

@ -1,10 +1,11 @@
from functools import reduce
from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet
from .models import Bill, Payment, PaymentMethod
def sum_amounts(entries):
return reduce(lambda acc, entry: acc + entry.amount, entries, 0)
def get_balance_for(user):
bills = sum_amounts(Bill.objects.filter(owner=user))
payments = sum_amounts(Payment.objects.filter(owner=user))
@ -18,3 +19,14 @@ def get_payment_method_for(user):
return method
return None
class ProductViewSet(mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
GenericViewSet):
"""
A customer-facing viewset that provides default `create()`, `retrieve()`
and `list()`.
"""
pass