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 initial = True
dependencies = [ dependencies = []
]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Transaction', name="Transaction",
fields=[ fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), (
('name', models.CharField(max_length=256)), "id",
('description', models.TextField()), models.UUIDField(
('value', models.DecimalField(decimal_places=2, max_digits=12)), default=uuid.uuid4,
('date', models.DateField()), 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( migrations.CreateModel(
name='Invoice', name="Invoice",
fields=[ fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), (
('name', models.CharField(max_length=256)), "id",
('file', models.FileField(upload_to='invoices/')), models.UUIDField(
('transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.transaction')), 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) value = models.DecimalField(max_digits=12, decimal_places=2)
date = models.DateField() date = models.DateField()
def __str__(self):
return f"{self.date} {self.name}: {self.value}"
class Invoice(models.Model): class Invoice(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=256) name = models.CharField(max_length=256)
file = models.FileField(upload_to="invoices/") file = models.FileField(upload_to="invoices/")
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE) transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE)
def __str__(self):
return f"{self.name}: {self.transaction}"