hackens-orga/hackens_orga/budget/serializers.py
2023-02-08 02:04:34 +01:00

23 lines
530 B
Python

from rest_framework import serializers
from .models import BudgetGroup, BudgetLine
class BudgetGroupSerializer(serializers.ModelSerializer):
total = serializers.SerializerMethodField()
def get_total(self, obj):
tot = 0
for i in obj.budgetline_set.all():
tot += i.amount
return tot
class Meta:
model = BudgetGroup
fields = "__all__"
class BudgetLineSerializer(serializers.ModelSerializer):
class Meta:
model = BudgetLine
fields = "__all__"