From a0f4e5ae543d48ab25084fcf3ad75c868f7ae256 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 19 May 2022 16:14:23 +0200 Subject: [PATCH] Add __str__ to models --- nummi/main/migrations/0001_initial.py | 47 +++++++++++++++++++-------- nummi/main/models.py | 6 ++++ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/nummi/main/migrations/0001_initial.py b/nummi/main/migrations/0001_initial.py index 5c9bedd..eec40f2 100644 --- a/nummi/main/migrations/0001_initial.py +++ b/nummi/main/migrations/0001_initial.py @@ -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", + ), + ), ], ), ] diff --git a/nummi/main/models.py b/nummi/main/models.py index 8f601e6..57099a7 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -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}"