Fix add snapshot page
This commit is contained in:
parent
a911b324b5
commit
63c7ab497e
2 changed files with 22 additions and 19 deletions
|
@ -32,6 +32,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% if categories %}
|
||||||
<h2>Plot</h2>
|
<h2>Plot</h2>
|
||||||
<div class="chart">
|
<div class="chart">
|
||||||
{% for cat in categories %}
|
{% for cat in categories %}
|
||||||
|
@ -83,6 +84,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if snapshot.transactions %}
|
{% if snapshot.transactions %}
|
||||||
<h2>Transactions ({{ sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
|
<h2>Transactions ({{ sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
|
||||||
|
|
|
@ -163,27 +163,28 @@ def snapshot(request, uuid=None):
|
||||||
"form": _form,
|
"form": _form,
|
||||||
}
|
}
|
||||||
|
|
||||||
context["categories"] = (
|
if _snapshot.transactions:
|
||||||
_snapshot.transactions.values("category", "category__name", "category__icon")
|
context["categories"] = (
|
||||||
.annotate(
|
_snapshot.transactions.values("category", "category__name", "category__icon")
|
||||||
sum=models.Sum("value"),
|
.annotate(
|
||||||
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
sum=models.Sum("value"),
|
||||||
sum_p=models.Sum("value", filter=models.Q(value__gt=0)),
|
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
||||||
)
|
sum_p=models.Sum("value", filter=models.Q(value__gt=0)),
|
||||||
.order_by("-sum")
|
|
||||||
)
|
|
||||||
context["cat_lim"] = max(
|
|
||||||
map(
|
|
||||||
abs,
|
|
||||||
context["categories"]
|
|
||||||
.aggregate(
|
|
||||||
max=models.Max("sum_p"),
|
|
||||||
min=models.Min("sum_m"),
|
|
||||||
)
|
)
|
||||||
.values(),
|
.order_by("-sum")
|
||||||
)
|
)
|
||||||
)
|
context["cat_lim"] = max(
|
||||||
context["cat_lim_m"] = -context["cat_lim"]
|
map(
|
||||||
|
abs,
|
||||||
|
context["categories"]
|
||||||
|
.aggregate(
|
||||||
|
max=models.Max("sum_p"),
|
||||||
|
min=models.Min("sum_m"),
|
||||||
|
)
|
||||||
|
.values(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
context["cat_lim_m"] = -context["cat_lim"]
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"main/snapshot.html",
|
"main/snapshot.html",
|
||||||
|
|
Loading…
Reference in a new issue