Note that there are some explanatory texts on larger screens.

plurals
  1. POremove items from queryset for nested regrouping
    primarykey
    data
    text
    <p>I've been working on a project that takes into consideration performance as the top priority therefore am trying to use single to queries at each page to collect all the needed information. </p> <p>Any who, I got to a point where I have one query set that need to be regrouped based on column (left, right, center) and then again regrouped based on title. The logic is working fine, but when the second regroup starts it will take the entire queryset meanwhile I only need to regroup items that are on the left or center..etc. so, I searched for functions to remove items from the queryset without hitting the database and only thing I could find was to build a custom template which is where I got stuck :) </p> <p>This is my query result </p> <pre><code> +------------+-------------------+------------+-----------+----+-----------+-----------+---------+----+-------------+-------------+ | 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 | +------------+-------------------+------------+-----------+----+-----------+-----------+---------+----+-------------+-------------+ </code></pre> <p>In my template, I did something like this </p> <pre><code> {% regroup dict by col_mapper as column_gr %} {% for column in column_gr %} {{ column.grouper }}&lt;br&gt; {% regroup column.list by main_title as item_gr %} {% for i in item_gr %} {{ i }} {% endfor %} {% endfor %} </code></pre> <p>The first regroup is working fine, but once it gets to the second regroup it regroups again the whole queryset while I want to only regroup where col_mapper is equal to col_mapper.grouper. I tried to build a custom tag, but most the approaches I know they will cause the queryset to hit the database again for filtering. </p> <p>Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload