Code

Opened 6 years ago

Last modified 13 months ago

#6285 new New feature

Cutting up a list of objects into a table with a given number of columns

Reported by: purdeaandrei Owned by: adrian
Component: Template system Version: master
Severity: Normal Keywords: feature_request
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Cutting up a list of objects into a table with a given number of columns

Approaches that might be bad:

  • it is not a good idea for the view to cut up the list, because the number of columns (N) is layout-related.
  • useing divisibleby is somewhat low-level, you are implementing a for loop, in a template language that is supposed to be high-level

Proposal:

  • to have a filter that will behave like this:
      {% for row in objectlist|tablecols:3 %}
         <tr>
           {% for item in row %}
               <td>
                    {{ item.content }}
               </td>
           {% endfor %}
         </tr>
      {% endfor %}
    

Attachments (1)

columns_rows_filters.diff (2.1 KB) - added by taylanpince 5 years ago.
Suggestion for filters to slice lists into rows and columns

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by anonymous

  • Keywords feature_request added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by adrian

  • Owner changed from nobody to adrian
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

I have template filters called bunch and bunchlong in my personal Django projects, and they do exactly this. I'd be happy to add them as default filters; I'd argue they're useful enough to be in the defaults.

comment:3 Changed 5 years ago by anonymous

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:4 Changed 5 years ago by taylanpince

  • Resolution fixed deleted
  • Status changed from closed to reopened

What is the status of this ticket? It seems to have been accepted, but then closed by an anonymous user? It would be great to have this feature in Django.

Changed 5 years ago by taylanpince

Suggestion for filters to slice lists into rows and columns

comment:5 Changed 3 years ago by julien

  • Needs documentation set
  • Needs tests set
  • Severity set to Normal
  • Type set to New feature

comment:6 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:8 Changed 13 months ago by aaugustin

  • Status changed from reopened to new

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from adrian to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.