Created goals and added to home and dashboards
This commit is contained in:
parent
cef8cb3f57
commit
dfedd64289
@ -90,7 +90,7 @@ class CategoryForm(forms.ModelForm):
|
||||
class GoalForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Goal
|
||||
fields = ['name', 'target_amount', 'category']
|
||||
fields = ['name', 'target_amount', 'category', "show_on_home"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
user = kwargs.pop('user')
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.10 on 2026-05-05 13:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('expenses', '0008_goal'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='goal',
|
||||
name='show_on_home',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
@ -248,6 +248,7 @@ class Goal(models.Model):
|
||||
target_amount = models.DecimalField(max_digits=12, decimal_places=2)
|
||||
category = models.ForeignKey("Category", on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
show_on_home = models.BooleanField(default=False)
|
||||
|
||||
def progress(self):
|
||||
"""
|
||||
|
||||
@ -390,4 +390,16 @@ tbody tr:hover {
|
||||
|
||||
.progress-fill.high {
|
||||
background: #2ecc71;
|
||||
}
|
||||
|
||||
.goals-widget {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.goal-card {
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
background: #f9f9f9;
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
{% extends "expenses/base.html" %}
|
||||
|
||||
{% load l10n %}
|
||||
|
||||
{% block title %}Dashboard{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -214,6 +216,39 @@
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- Goals -->
|
||||
<!-- ========================= -->
|
||||
|
||||
<h3>Objetivos</h3>
|
||||
{% if goals %}
|
||||
<div class="goals-widget">
|
||||
{% for goal in goals %}
|
||||
<div class="goal-card">
|
||||
<strong>{{ goal.name }}</strong>
|
||||
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill
|
||||
{% if goal.percentage < 50 %} low
|
||||
{% elif goal.percentage < 80 %} medium
|
||||
{% else %} high
|
||||
{% endif %}"
|
||||
style="width: {{ goal.percentage|unlocalize }}%"></div>
|
||||
</div>
|
||||
|
||||
<span class="progress-label">
|
||||
{{ goal.progress|floatformat:1 }}€ / {{ goal.target_amount|floatformat:1 }}€ ({{ goal.percentage|floatformat:1 }}%)
|
||||
</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>No hay objetivos.</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- Categories -->
|
||||
<!-- ========================= -->
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
{% extends "expenses/base.html" %}
|
||||
|
||||
{% load l10n %}
|
||||
|
||||
{% block title %}Home{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -60,4 +62,30 @@
|
||||
|
||||
</section>
|
||||
|
||||
<h3>Objetivos</h3>
|
||||
{% if goals %}
|
||||
<div class="goals-widget">
|
||||
{% for goal in goals %}
|
||||
<div class="goal-card">
|
||||
<strong>{{ goal.name }}</strong>
|
||||
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill
|
||||
{% if goal.percentage < 50 %} low
|
||||
{% elif goal.percentage < 80 %} medium
|
||||
{% else %} high
|
||||
{% endif %}"
|
||||
style="width: {{ goal.percentage|unlocalize }}%"></div>
|
||||
</div>
|
||||
|
||||
<span class="progress-label">
|
||||
{{ goal.progress|floatformat:1 }}€ / {{ goal.target_amount|floatformat:1 }}€ ({{ goal.percentage|floatformat:1 }}%)
|
||||
</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>No tienes objetivos aún.</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@ -93,6 +93,8 @@ def home(request):
|
||||
}
|
||||
)
|
||||
|
||||
goals = Goal.objects.filter(owner=request.user, show_on_home=True)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"expenses/home.html",
|
||||
@ -104,6 +106,7 @@ def home(request):
|
||||
"kpi_categories": kpi_categories,
|
||||
"mini_chart_labels": [x["label"] for x in mini_data],
|
||||
"mini_chart_data": [x["total"] for x in mini_data],
|
||||
"goals": goals,
|
||||
},
|
||||
)
|
||||
|
||||
@ -497,6 +500,9 @@ def dashboard(request):
|
||||
}
|
||||
)
|
||||
|
||||
# Goals
|
||||
goals = Goal.objects.filter(owner=request.user)
|
||||
|
||||
# Send the data to the dashboard
|
||||
return render(
|
||||
request,
|
||||
@ -527,6 +533,7 @@ def dashboard(request):
|
||||
"kpi_balance": kpi_balance,
|
||||
"accounts_charts": accounts_charts,
|
||||
"period": period,
|
||||
"goals": goals,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user