Browse Source

Сделал фильтрацию по колонкам

devel
Dmitry 9 years ago
parent
commit
5d1bc73343
  1. 21
      devapp/templates/devapp/devices.html
  2. 14
      devapp/views.py

21
devapp/templates/devapp/devices.html

@ -14,9 +14,24 @@
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>{% trans 'Ip address' %}</th>
<th>{% trans 'Comment' %}</th>
<th width="250">{% trans 'Device type' %}</th>
<th>
<a href="{% url 'devapp:devs' %}?order_by=ip_address&dir={{ dir|default:"down" }}">
{% trans 'Ip address' %}
</a>
{% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th>
<th>
<a href="{% url 'devapp:devs' %}?order_by=comment&dir={{ dir|default:"down" }}">
{% trans 'Comment' %}
</a>
{% if order_by == 'comment' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th>
<th width="250">
<a href="{% url 'devapp:devs' %}?order_by=devtype&dir={{ dir|default:"down" }}">
{% trans 'Device type' %}
</a>
{% if order_by == 'devtype' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
</th>
<th width="100">Do</th>
</tr>
</thead>

14
devapp/views.py

@ -7,7 +7,7 @@ from django.utils.translation import ugettext as _
from easysnmp import EasySNMPTimeoutError
from .models import Device
from mydefs import pag_mn, res_success, res_error, only_admins, ping
from mydefs import pag_mn, res_success, res_error, only_admins, ping, order_helper
from .forms import DeviceForm
@ -15,10 +15,20 @@ from .forms import DeviceForm
@only_admins
def devices(request):
devs = Device.objects.all()
# фильтр
dr, field = order_helper(request)
if field:
devs = devs.order_by(field)
print(type(request.GET), request.GET)
import django.http.request
devs = pag_mn(request, devs)
return render(request, 'devapp/devices.html', {
'devices': devs
'devices': devs,
'dir': dr,
'order_by': request.GET.get('order_by')
})

Loading…
Cancel
Save