forked from uncloud/uncloud
Introduce custom ProductViewSet preventing customer from updating
products
This commit is contained in:
parent
33cc2b2111
commit
b3bbfafa04
3 changed files with 19 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue