30 lines
943 B
Python
30 lines
943 B
Python
import uuid
|
|
from django.db import models
|
|
from django.forms import ModelForm
|
|
|
|
|
|
class Transaction(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
name = models.CharField(max_length=256)
|
|
description = models.TextField()
|
|
value = models.DecimalField(max_digits=12, decimal_places=2)
|
|
date = models.DateField()
|
|
|
|
def __str__(self):
|
|
return f"{self.date} {self.name}: {self.value}€"
|
|
|
|
|
|
class TransactionForm(ModelForm):
|
|
class Meta:
|
|
model = Transaction
|
|
fields = ["name", "description", "value", "date"]
|
|
|
|
|
|
class Invoice(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
name = models.CharField(max_length=256)
|
|
file = models.FileField(upload_to="invoices/")
|
|
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
return f"{self.name}: {self.transaction}"
|