hackens-orga/hackens_orga/budget/models.py
2023-02-16 19:10:23 +01:00

34 lines
1,011 B
Python

from datetime import date
from agent.models import Agent
from django.db import models
class BudgetLine(models.Model):
amount = models.DecimalField(max_digits=12, decimal_places=2)
author = models.ForeignKey(Agent, on_delete=models.PROTECT)
comment = models.TextField(blank=True)
date = models.DateField(default=date.today)
facture = models.FileField(upload_to="factures/", null=True, blank=True)
group = models.ForeignKey("BudgetGroup", on_delete=models.CASCADE)
title = models.CharField(max_length=255)
def __str__(self):
return f"{self.title}"
def __repr__(self):
return f"BudgetLine_{self.title}_{self.amount}"
class BudgetGroup(models.Model):
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
def get_total(self):
return sum(i.amount for i in self.budgetline_set.all())
def __str__(self):
return f"{self.name}"
def __repr__(self):
return f"BudgetGroup_{self.name}"