Add __str__ to models

This commit is contained in:
Edgar P. Burkhart 2022-05-19 16:14:23 +02:00
parent 0b58580a00
commit a0f4e5ae54
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 40 additions and 13 deletions

View file

@ -9,27 +9,48 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
]
dependencies = []
operations = [
migrations.CreateModel(
name='Transaction',
name="Transaction",
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=256)),
('description', models.TextField()),
('value', models.DecimalField(decimal_places=2, max_digits=12)),
('date', models.DateField()),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=256)),
("description", models.TextField()),
("value", models.DecimalField(decimal_places=2, max_digits=12)),
("date", models.DateField()),
],
),
migrations.CreateModel(
name='Invoice',
name="Invoice",
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=256)),
('file', models.FileField(upload_to='invoices/')),
('transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.transaction')),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=256)),
("file", models.FileField(upload_to="invoices/")),
(
"transaction",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="main.transaction",
),
),
],
),
]

View file

@ -9,9 +9,15 @@ class Transaction(models.Model):
value = models.DecimalField(max_digits=12, decimal_places=2)
date = models.DateField()
def __str__(self):
return f"{self.date} {self.name}: {self.value}"
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}"