Add default account field

Fixes #3 again
This commit is contained in:
Edgar P. Burkhart 2022-12-31 19:08:09 +01:00
parent d9304db43d
commit 08227d3af3
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
4 changed files with 30 additions and 1 deletions

View file

@ -18,6 +18,7 @@ class AccountForm(NummiForm):
fields = [ fields = [
"name", "name",
"icon", "icon",
"default",
] ]

View file

@ -0,0 +1,18 @@
# Generated by Django 4.1.4 on 2022-12-31 18:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("main", "0023_auto_20221231_1741"),
]
operations = [
migrations.AddField(
model_name="account",
name="default",
field=models.BooleanField(default=False, verbose_name="Default"),
),
]

View file

@ -48,6 +48,14 @@ class Account(CustomModel):
default="building-columns", default="building-columns",
verbose_name=_("Icon"), verbose_name=_("Icon"),
) )
default = models.BooleanField(default=False, verbose_name=_("Default"))
def save(self, *args, **kwargs):
if self.default:
for ac in Account.objects.filter(user=self.user, default=True):
ac.default = False
ac.save()
super().save(*args, **kwargs)
def __str__(self): def __str__(self):
return str(self.name) return str(self.name)

View file

@ -133,7 +133,9 @@ class SnapshotCreateView(NummiCreateView):
"initial": { "initial": {
"account": ( "account": (
self.kwargs.get("account") self.kwargs.get("account")
or Account.objects.filter(user=self.request.user).first() or Account.objects.filter(user=self.request.user)
.order_by("-default")
.first()
), ),
}, },
} }