从查询集中删除项目以进行嵌套重组

| 我一直在从事一个将性能作为首要任务的项目,因此我试图在每个页面上使用单个查询来收集所有需要的信息。 任何人,我都知道我有一个查询集需要根据列(左,右,中心)进行重新组合,然后再次根据标题进行重新组合。逻辑工作正常,但是当第二次重新组合开始时,它将占用整个查询集,而我只需要重新组合左边或中间的项目。因此,我搜索了无需删除数据库即可从queryset中删除项目的函数,而我唯一能找到的就是建立自定义模板,而这正是我遇到的麻烦:) 这是我的查询结果
    +------------+-------------------+------------+-----------+----+-----------+-----------+---------+----+-------------+-------------+
| col_mapper | list_title        | main_title | list_slug | id | slug      | is_active | site_id | id | domain      | name        |
+------------+-------------------+------------+-----------+----+-----------+-----------+---------+----+-------------+-------------+
| L          | gadget            | for sale   | gadget    |  2 | for-sale  |         1 |       1 |  1 | example.com | example.com |
| L          | furniture         | for sale   | frnture   |  2 | for-sale  |         1 |       1 |  1 | example.com | example.com |
| L          | engines           | for sale   | engines   |  2 | for-sale  |         1 |       1 |  1 | example.com | example.com |
| L          | women seeking men | personals  | wsm       |  1 | personals |         1 |       1 |  1 | example.com | example.com |
| L          | missed connection | personals  | misd-conn |  1 | personals |         1 |       1 |  1 | example.com | example.com |
| L          | men seeking women | personals  | msw       |  1 | personals |         1 |       1 |  1 | example.com | example.com |
| R          | massage           | services   | massage   |  3 | srvces    |         1 |       1 |  1 | example.com | example.com |
| R          | computers         | services   | compters  |  3 | srvces    |         1 |       1 |  1 | example.com | example.com |
+------------+-------------------+------------+-----------+----+-----------+-----------+---------+----+-------------+-------------+
在我的模板中,我做了这样的事情
            {% regroup dict by col_mapper as column_gr %}

        {% for column in column_gr %}                
            {{ column.grouper }}<br>

            {% regroup column.list by main_title as item_gr %}
                {% for i in item_gr %}
                    {{ i }}
                {% endfor %}
        {% endfor %}
第一次重新组合工作正常,但是一旦到达第二次重新组合,它将再次重新组合整个查询集,而我只想重新组合,其中col_mapper等于col_mapper.grouper。我试图构建一个自定义标签,但是我知道大多数方法都会使queryset再次命中数据库以进行过滤。 有什么建议么?     
已邀请:
我尚未对此进行测试,但是您可以尝试:
{% regroup dict by col_mapper as column_gr %}

{% for column in column_gr %}                
    {{ column.grouper }}<br>
    {# assign the grouper to another variable #}
    {% with column.grouper as grouper %}
        {% regroup grouper by main_title as item_gr %}
        {% for i in item_gr %}
            {{ i }}
        {% endfor %}
    {% endwith %}
{% endfor %}
    

要回复问题请先登录注册