Skip to content
Snippets Groups Projects
Commit 79da6b1a authored by Edmar's avatar Edmar
Browse files

Added search by name in admin page

parent 27d85617
No related branches found
No related tags found
No related merge requests found
......@@ -40,13 +40,15 @@ def elections(request):
page = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 25))
q = request.GET.get('q','')
elections = Election.objects.all().order_by('-created_at')
elections = Election.objects.filter(name__icontains = q)
elections.all().order_by('-created_at')
elections_paginator = Paginator(elections, limit)
elections_page = elections_paginator.page(page)
return render_template(request, "stats_elections", {'elections' : elections_page.object_list, 'elections_page': elections_page,
'limit' : limit})
'limit' : limit, 'q': q})
def recent_votes(request):
user = require_admin(request)
......
......@@ -4,15 +4,23 @@
{% block content %}
<h1>Elections</h1>
<p>
<form method="get" action="{% url "helios.stats_views.elections" %}">
<b>search</b>: <input type="text" name="q" value="{{q}}"/>
<input class="small button" type="submit" value="search" /> <a class="small button" href="?">clear search</a>
</form>
</p>
<p>
{% if elections_page.has_previous %}
<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}">previous {{limit}}</a> &nbsp;&nbsp;
<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}&q={{q}}">previous {{limit}}</a> &nbsp;&nbsp;
{% endif %}
Elections {{elections_page.start_index}} - {{elections_page.end_index}}&nbsp;&nbsp;
{% if elections_page.has_next %}
<a href="?page={{elections_page.next_page_number}}&limit={{limit}}">next {{limit}}</a> &nbsp;&nbsp;
<a href="?page={{elections_page.next_page_number}}&limit={{limit}}&q={{q}}">next {{limit}}</a> &nbsp;&nbsp;
{% endif %}
</p>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment