diff --git a/nummi/main/views.py b/nummi/main/views.py index 47aaf98..b0237a3 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -26,19 +26,22 @@ class IndexView(LoginRequiredMixin, TemplateView): template_name = "main/index.html" def get_context_data(self, **kwargs): - _max = 10 - res = super().get_context_data(**kwargs) | { + _max = 8 + _transactions = Transaction.objects.filter(user=self.request.user) + _snapshots = Snapshot.objects.filter(user=self.request.user) + + res = { "accounts": Account.objects.filter(user=self.request.user), - "transactions": Transaction.objects.filter(user=self.request.user)[:10], + "transactions": _transactions[:_max], "categories": Category.objects.filter(user=self.request.user), - "snapshots": Snapshot.objects.filter(user=self.request.user)[:10], + "snapshots": _snapshots[:_max], } - if res["transactions"].count() == 10: + if _transactions.count() > _max: res["transactions_url"] = reverse_lazy("transactions") - if res["snapshots"].count() == 10: + if _snapshots.count() > _max: res["snapshots_url"] = reverse_lazy("snapshots") - return res + return super().get_context_data(**kwargs) | res class UserMixin(LoginRequiredMixin):