28 lines
900 B
Python
28 lines
900 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"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"BudgetGroup_{self.name}"
|