diff --git a/nummi/main/templates/main/account_form.html b/nummi/main/templates/main/account_form.html
index 358d6cf..292c2b0 100644
--- a/nummi/main/templates/main/account_form.html
+++ b/nummi/main/templates/main/account_form.html
@@ -19,7 +19,7 @@
{% csrf_token %}
{{ form }}
- {% if snapshots %}
+ {% if not form.instance.adding %}
{% translate "Statements" %}
{% include "main/table/snapshot.html" %}
{% endif %}
diff --git a/nummi/main/templates/main/snapshot_form.html b/nummi/main/templates/main/snapshot_form.html
index 1e9a19e..515c06b 100644
--- a/nummi/main/templates/main/snapshot_form.html
+++ b/nummi/main/templates/main/snapshot_form.html
@@ -71,7 +71,7 @@
{% endfor %}
{% endif %}
- {% if snapshot.transaction_set.all %}
+ {% if not snapshot.adding %}
{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})
{% include "main/table/transaction.html" %}
{% endif %}
diff --git a/nummi/main/views.py b/nummi/main/views.py
index c9dea90..a979e65 100644
--- a/nummi/main/views.py
+++ b/nummi/main/views.py
@@ -134,18 +134,27 @@ class AccountUpdateView(NummiUpdateView):
form_class = AccountForm
def get_context_data(self, **kwargs):
+ _max = 8
data = super().get_context_data(**kwargs)
account = data["form"].instance
- return data | {
- "transactions": account.transaction_set.all()[:8],
- "transactions_url": reverse_lazy(
+
+ _transactions = account.transaction_set.all()
+ if _transactions.count() > _max:
+ data["transactions_url"] = reverse_lazy(
"account_transactions", args=(account.pk,)
- ),
+ )
+ _snapshots = account.snapshot_set.all()
+ if _snapshots.count() > _max:
+ data["snapshots_url"] = reverse_lazy(
+ "account_snapshots", args=(account.pk,)
+ )
+
+ return data | {
+ "transactions": _transactions[:8],
"new_snapshot_url": reverse_lazy(
"snapshot", kwargs={"account": account.pk}
),
- "snapshots": account.snapshot_set.all()[:8],
- "snapshots_url": reverse_lazy("account_snapshots", args=(account.pk,)),
+ "snapshots": _snapshots[:8],
}
@@ -193,16 +202,21 @@ class SnapshotUpdateView(NummiUpdateView):
form_class = SnapshotForm
def get_context_data(self, **kwargs):
+ _max = 8
data = super().get_context_data(**kwargs)
snapshot = data["form"].instance
+
+ _transactions = snapshot.transaction_set.all()
+ if _transactions.count() > _max:
+ data["transactions_url"] = reverse_lazy(
+ "snapshot_transactions", args=(snapshot.pk,)
+ )
+
return data | {
"new_transaction_url": reverse_lazy(
"transaction", kwargs={"snapshot": snapshot.pk}
),
- "transactions": snapshot.transaction_set.all()[:8],
- "transactions_url": reverse_lazy(
- "snapshot_transactions", args=(snapshot.pk,)
- ),
+ "transactions": _transactions[:_max],
}