Opened 9 years ago

Closed 2 years ago

#6285 closed New feature (wontfix)

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

Reported by: Purdea Andrei Owned by: Adrian Holovaty
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 Taylan Pince 8 years ago.
Suggestion for filters to slice lists into rows and columns

Download all attachments as: .zip

Change History (10)

comment:1 Changed 9 years ago by anonymous

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

comment:2 Changed 9 years ago by Adrian Holovaty

Owner: changed from nobody to Adrian Holovaty
Status: newassigned
Triage Stage: UnreviewedAccepted

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 8 years ago by anonymous

Resolution: fixed
Status: assignedclosed

comment:4 Changed 8 years ago by Taylan Pince

Resolution: fixed
Status: closedreopened

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 8 years ago by Taylan Pince

Attachment: columns_rows_filters.diff added

Suggestion for filters to slice lists into rows and columns

comment:5 Changed 6 years ago by Julien Phalip

Needs documentation: set
Needs tests: set
Severity: Normal
Type: New feature

comment:6 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 Changed 4 years ago by Aymeric Augustin

Status: reopenednew

comment:9 Changed 2 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

Considering:

  • how long this ticket has languished, with little demand,
  • that it can easily be implemented in a third-part library,
  • the current trend not to extend the template system further,

I'm going to close it.

Note: See TracTickets for help on using tickets.
Back to Top