2023-01-16 18:50:12 +01:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2023-02-08 02:04:34 +01:00
|
|
|
from .models import BudgetGroup, BudgetLine
|
2023-01-16 18:50:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
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__"
|