diff --git a/nummi/main/templates/main/account_form.html b/nummi/main/templates/main/account_form.html index ce55c42..0694c58 100644 --- a/nummi/main/templates/main/account_form.html +++ b/nummi/main/templates/main/account_form.html @@ -19,4 +19,5 @@ {% csrf_token %} {{ form }} + {% include "main/table/transaction.html" %} {% endblock %} diff --git a/nummi/main/templates/main/category_form.html b/nummi/main/templates/main/category_form.html index 01e17fe..b2c04cf 100644 --- a/nummi/main/templates/main/category_form.html +++ b/nummi/main/templates/main/category_form.html @@ -23,8 +23,6 @@ Graph representing value over time

{% translate "Transactions" %}

- {% with transactions=form.instance.transactions %} - {% include "main/table/transaction.html" %} - {% endwith %} + {% include "main/table/transaction.html" %} {% endif %} {% endblock %} diff --git a/nummi/main/templates/main/snapshot_form.html b/nummi/main/templates/main/snapshot_form.html index 4f387c3..1e9a19e 100644 --- a/nummi/main/templates/main/snapshot_form.html +++ b/nummi/main/templates/main/snapshot_form.html @@ -73,9 +73,7 @@ {% endif %} {% if snapshot.transaction_set.all %}

{% translate "Transactions" %} ({{ snapshot.sum|pmvalue }} / {{ snapshot.diff|pmvalue }})

- {% with transactions=snapshot.transaction_set.all %} - {% include "main/table/transaction.html" %} - {% endwith %} + {% include "main/table/transaction.html" %} {% endif %} {% endwith %} {% endblock %} diff --git a/nummi/main/urls.py b/nummi/main/urls.py index 0bbb210..48af125 100644 --- a/nummi/main/urls.py +++ b/nummi/main/urls.py @@ -35,6 +35,11 @@ urlpatterns = [ name="invoice", ), path("category/", views.CategoryUpdateView.as_view(), name="category"), + path( + "category//transactions", + views.CategoryTListView.as_view(), + name="category_transactions", + ), path("snapshot/", views.SnapshotUpdateView.as_view(), name="snapshot"), path( "snapshot//transactions", diff --git a/nummi/main/views.py b/nummi/main/views.py index b0237a3..ca90654 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -120,6 +120,16 @@ class AccountUpdateView(NummiUpdateView): model = Account form_class = AccountForm + def get_context_data(self, **kwargs): + data = super().get_context_data(**kwargs) + account = data["form"].instance + return data | { + "transactions": account.transaction_set.all()[:8], + "transactions_url": reverse_lazy( + "account_transactions", args=(account.pk,) + ), + } + class TransactionUpdateView(NummiUpdateView): model = Transaction @@ -149,11 +159,31 @@ class CategoryUpdateView(NummiUpdateView): model = Category form_class = CategoryForm + def get_context_data(self, **kwargs): + data = super().get_context_data(**kwargs) + category = data["form"].instance + return data | { + "transactions": category.transaction_set.all()[:8], + "transactions_url": reverse_lazy( + "category_transactions", args=(category.pk,) + ), + } + class SnapshotUpdateView(NummiUpdateView): model = Snapshot form_class = SnapshotForm + def get_context_data(self, **kwargs): + data = super().get_context_data(**kwargs) + snapshot = data["form"].instance + return data | { + "transactions": snapshot.transaction_set.all()[:8], + "transactions_url": reverse_lazy( + "snapshot_transactions", args=(snapshot.pk,) + ), + } + class AccountDeleteView(NummiDeleteView): model = Account @@ -217,6 +247,11 @@ class SnapshotTListView(TransactionListView): return super().get_queryset().filter(snapshot=self.kwargs.get("pk")) +class CategoryTListView(TransactionListView): + def get_queryset(self): + return super().get_queryset().filter(category=self.kwargs.get("pk")) + + class SearchView(TransactionListView): def post(self, *args, **kwargs): return redirect("search", search=self.request.POST.get("search"))