Решение, которое я нашел:
В urls.conf добавьте шаблон:
(r'^main/ligacao/$', 'main.admin_views.ticket_list_result')
Затем в admin_views.py создайте метод ticket_list_result
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.db.models import Count
def ticket_list_result (request):
# ... parses, fetches, etc...
# Get companies without tickets
companies = Company.objects.annotate(n = Count('ticket')).filter(n = 0)
results = list()
for c in companies:
# Get tickets for the company
tickets = Ticket.objects.filter(company = c.id)
# Construct a dict to return to the view
results.append({
'company': c,
# ... any other desired info
})
return render_to_response(
"admin/view_template.html",
{'results' : results },
RequestContext(request, {}),
)
И перечислите эти результаты в представлении "admin / view_template.html":
{% block result_list %}
<table cellspacing="0" id="result_list">
<thead>
<tr>
<th>Company</th>
<!-- other columns -->
</tr>
</thead>
<tbody>
{% for r in results %}
<tr class="{% cycle 'row1' 'row2' %}">
<th>{{ r.company }}</th>
<!-- other company info -->
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}