Modified filters for expenses lit
This commit is contained in:
parent
89b9a6b016
commit
c4ec35e14d
@ -7,15 +7,27 @@
|
|||||||
<h1>Mis gastos</h1>
|
<h1>Mis gastos</h1>
|
||||||
|
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<label>
|
<select name="year">
|
||||||
Año:
|
<option value="">Año</option>
|
||||||
<input type="number" name="year" value="{{ selected_year }}">
|
{% for y in year_list %}
|
||||||
</label>
|
<option value="{{ y }}"
|
||||||
|
{% if selected_year == y %}selected{% endif %}
|
||||||
|
>
|
||||||
|
{{ y }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
<label>
|
<select name="month">
|
||||||
Mes:
|
<option value="">Mes</option>
|
||||||
<input type="number" name="month" value="{{ selected_month }}">
|
{% for m in months %}
|
||||||
</label>
|
<option value="{{ m }}"
|
||||||
|
{% if selected_month == m %}selected{% endif %}
|
||||||
|
>
|
||||||
|
{{ m }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
Categoría:
|
Categoría:
|
||||||
@ -23,7 +35,7 @@
|
|||||||
<option value="">Todas</option>
|
<option value="">Todas</option>
|
||||||
{% for cat in categories %}
|
{% for cat in categories %}
|
||||||
<option value="{{ cat.id }}"
|
<option value="{{ cat.id }}"
|
||||||
{% if selected_category == cat.id|stringformat:"s" %}selected{% endif%}
|
{% if selected_category == cat.id %}selected{% endif%}
|
||||||
>
|
>
|
||||||
{{ cat.name }}
|
{{ cat.name }}
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@ -99,17 +99,21 @@ def home(request):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def expense_list(request):
|
def expense_list(request):
|
||||||
expenses = (
|
expenses = Expense.objects.filter(owner=request.user)
|
||||||
Expense.objects
|
|
||||||
.filter(owner=request.user)
|
categories = Category.objects.filter(owner=request.user)
|
||||||
.select_related('category')
|
|
||||||
.order_by('-date')
|
year_list = (
|
||||||
|
Expense.objects.filter(owner=request.user)
|
||||||
|
.dates('date', 'year')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
months = list(range(1, 13))
|
||||||
|
|
||||||
# Filters
|
# Filters
|
||||||
year = request.GET.get('year')
|
year = _get_int(request.GET.get('year'))
|
||||||
month = request.GET.get('month')
|
month = _get_int(request.GET.get('month'))
|
||||||
category = request.GET.get('category')
|
category = _get_int(request.GET.get('category'))
|
||||||
|
|
||||||
if year:
|
if year:
|
||||||
expenses = expenses.filter(date__year=year)
|
expenses = expenses.filter(date__year=year)
|
||||||
@ -120,7 +124,7 @@ def expense_list(request):
|
|||||||
if category:
|
if category:
|
||||||
expenses = expenses.filter(category_id=category)
|
expenses = expenses.filter(category_id=category)
|
||||||
|
|
||||||
categories = Category.objects.filter(owner=request.user).order_by('name')
|
expenses = expenses.order_by('-date')
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
paginator = Paginator(expenses, 10)
|
paginator = Paginator(expenses, 10)
|
||||||
@ -131,12 +135,14 @@ def expense_list(request):
|
|||||||
request,
|
request,
|
||||||
'expenses/expense_list.html',
|
'expenses/expense_list.html',
|
||||||
{
|
{
|
||||||
'expenses': expenses,
|
'expenses': page_obj,
|
||||||
'categories': categories,
|
'page_obj': page_obj,
|
||||||
'selected_year': year,
|
'selected_year': year,
|
||||||
'selected_month': month,
|
'selected_month': month,
|
||||||
'selected_category': category,
|
'selected_category': category,
|
||||||
'page_obj': page_obj,
|
'categories': categories,
|
||||||
|
'year_list': [y.year for y in year_list],
|
||||||
|
'months': months,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user