parent
d9304db43d
commit
08227d3af3
4 changed files with 30 additions and 1 deletions
|
@ -18,6 +18,7 @@ class AccountForm(NummiForm):
|
||||||
fields = [
|
fields = [
|
||||||
"name",
|
"name",
|
||||||
"icon",
|
"icon",
|
||||||
|
"default",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
18
nummi/main/migrations/0024_account_default.py
Normal file
18
nummi/main/migrations/0024_account_default.py
Normal 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"),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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)
|
||||||
|
|
|
@ -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()
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue