Only show all transactions line when number is strictly higher than showed

This commit is contained in:
Edgar P. Burkhart 2022-12-31 11:13:46 +01:00
parent 7c5e804aba
commit 2a898c706e
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
1 changed files with 10 additions and 7 deletions

View File

@ -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):