我正在尝试将不同的查询集传递给我的模板,因为我已经覆盖了这样的get_context_data:
class MainList(ListView):
queryset = models.Tickets.objects.order_by('-pk')
template_name = 'index.html'
context_object_name = 'tickets_desc_pk'
paginate_by = 5
def get_context_data(self, **kwargs):
context = super(MainList, self).get_context_data(**kwargs)
context['tickets_inc_date'] = models.Tickets.objects.order_by('set_date')
return context
一切顺利,直到我决定对我的表进行分页,paginate_by仅适用于主要上下文(tickets_desc_pk)。 有谁知道,如何分页另一个上下文?或者我应该通过JS / JQuery在客户端执行此操作吗?
<table class="table table-condensed">
<tbody>
{% for ticket in tickets_inc_date %}
<tr>
<td>{{ ticket.pk }}</td>
<td>{{ ticket.topic }}</td>
<td>{{ ticket.set_date }}</td>
<td>{{ ticket.priority }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table table-condensed">
<tbody>
{% for ticket in tickets_inc_date %}
<tr>
<td>{{ ticket.pk }}</td>
<td>{{ ticket.topic }}</td>
</tr>
{% endfor %}
</tbody>
</table>