我目前正在重新组合一些数据,然后在列中显示这些数据,同时还使用分页。但是,由于原始数据的排序,在某些情况下,第 1 列有 1 个条目,但实际上总共有 5 或 6 个条目,但它们会在不同的页面上,是否可以重新组合数据,以便每页的项目是由分组项目的数量所占据的?
我考虑过在将数据发布到页面之前对数据进行排序,但那样只会显示每页一列类型(可能有 1 或 n 个类型/列,id 喜欢在一页上)
注:以下样本数据并非实际数据,
下面的例子希望能让事情更清楚
原始数据:
ID Type Item
----------------------------
9 Fruit Apple
15 Meat Beef
18 Fruit Lemon
99 Fruit Orange
9 Fruit Grape
77 Meat Chicken
分页和分组数据当前输出
Meat Fruit
------- -------
Beef Apple
Lemon
page 1 of 2 (3 items per page)
Meat Fruit
------- -------
Chicken Orange
Grape
page 2 of 2 (3 items per page)
期望的输出
Meat Fruit
------- -------
Beef Apple
Chicken Lemon
Orange
page 1 of 2 (3 items per group per page)
Meat Fruit
------- -------
Grape
page 2 of 2 (3 items per group per page)
这是我当前的模板:
{% include 'search/page_nav.html' %}
{% with results.object_list as results_list %}
{% regroup results_list|dictsort:"model_name" by model_name as grouped_objects %}
{% for ct in grouped_objects %}
<div class="col-4">
<h3 class="text-capitalize">{{ ct.grouper }}'s</h3>
{% for result in ct.list %}
<div class="col-12 results">
<div class="pt-4 border-bottom">
<a class="page-url h4 text-primary" href="{{ result.object.get_absolute_url }}">{{ result.object.get_search_title }}</a>
<p class="page-description mt-1 text-muted"> {{ result.object.get_search_text|safe }}</p>
</div>
</div>
{% endfor %}
</div>
{% empty %}
<p class="lead">Although I am a guru, I am lacking sentience. One must ask a specific question to recieve a specific answer.</p>
{% endfor %}
{% endwith %}
{% include 'search/page_nav.html' %}
长风秋雁
相关分类