浏览代码

Construyendo dashboard

Celestino Rey 1 年之前
父节点
当前提交
6b3013fb11
共有 4 个文件被更改,包括 39 次插入 和 22 次删除
  1. 4 0
      .gitignore
  2. 二进制
      db.sqlite3
  3. 1 13
      finanzas/views.py
  4. 34 9
      templates/dashboard.html

+ 4 - 0
.gitignore

@@ -1 +1,5 @@
+db.sqlite3
+.gitignore
+.DS_Store
+venv
 __pycache__/

二进制
db.sqlite3


+ 1 - 13
finanzas/views.py

@@ -9,27 +9,15 @@ from django.contrib.auth.decorators import login_required
 def dashboard(request):
     movimientos = Movimiento.objects.filter(usuario=request.user).order_by('-fecha')
 
-    form = FiltroForm(request.GET or None)
-    form.fields['cuenta'].queryset = Cuenta.objects.filter(usuario=request.user)
-
-    if form.is_valid():
-        if form.cleaned_data['fecha_inicio']:
-            movimientos = movimientos.filter(fecha__gte=form.cleaned_data['fecha_inicio'])
-        if form.cleaned_data['fecha_fin']:
-            movimientos = movimientos.filter(fecha__lte=form.cleaned_data['fecha_fin'])
-        if form.cleaned_data['cuenta']:
-            cuenta = form.cleaned_data['cuenta']
-            movimientos = movimientos.filter(models.Q(cuenta_origen=cuenta) | models.Q(cuenta_destino=cuenta))
-
     ingresos = sum(m.monto for m in movimientos if m.cuenta_destino.tipo == 'ingreso')
     gastos = sum(m.monto for m in movimientos if m.cuenta_origen.tipo == 'gasto')
     balance = ingresos - gastos
+
     return render(request, 'dashboard.html', {
         'movimientos': movimientos,
         'ingresos': ingresos,
         'gastos': gastos,
         'balance': balance,
-        'form': form,
         'user': request.user,
     })
 

+ 34 - 9
templates/dashboard.html

@@ -34,19 +34,44 @@
         <h2>Balance: {{ balance }}</h2>
         <p>Ingresos: {{ ingresos }} | Gastos: {{ gastos }}</p>
 
+        <h3>Movimientos recientes</h3>
+        <table width="100%">
+            <thead>
+                <tr>
+                    <td>Fecha</td>
+                    <td>Origen</td>
+                    <td>Destino</td>
+                    <td>Cantidad</td>
+                    <td>Descripción</td>
+                </tr>
+            </thead>
 
-        <h3>Filtrar movimientos</h3>
-        <form method="get">
-            {{ form.as_p }}
-            <button type="submit">Filtrar</button>
-        </form>
+            <tbody>
 
-        <h3>Movimientos recientes</h3>
-        <ul>
             {% for m in movimientos %}
-                <li>{{ m.fecha }} - {{ m.categoria.nombre }}: {{ m.monto }} ({{ m.descripcion }})</li>
+                <tr>
+                    <td class="movimiento">
+                        {{ m.fecha }}
+                    </td>                                     
+                    
+                    <td class="movimiento">
+                        {{ m.cuenta_origen }}
+                    </td>
+                    <td class="movimiento">
+                        {{ m.cuenta_destino }}
+                    </td>
+
+                    <td class="movimiento">
+                        {{ m.monto }} 
+                    </td>
+
+                    <td class="movimiento">
+                        {{ m.descripcion }}
+                    </td>
+                </tr>
             {% endfor %}
-        </ul>
+            </tbody>
+        </table>
     </div>
 </section>
 {% endblock %}