Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting a list into "N" chunks #40

Open
asmaloney opened this issue Aug 14, 2017 · 0 comments
Open

Splitting a list into "N" chunks #40

asmaloney opened this issue Aug 14, 2017 · 0 comments

Comments

@asmaloney
Copy link
Contributor

I'm trying to take a list of objects (QList<QObject *>), split it into "N" chunks, and build a separate (HTML) table for each chunk.

I'm doing something like:

  {% range objectList.count as startNum %}
    {% if startNum|divisibleby:16 %}
      {% include "table.html.django" %}
    {% endif %}
  {% endrange %}

I've tried this for table.html.django:

<table>
     <thead><tr><th>Name</th></tr></thead>
     <tbody>
       {% range startNum startNum|add:16 as num %}
       <tr><td>{{ num }} {{ objectList.num.name }}</td></tr>
       {% endrange %}
   </tbody>
 </table>

But that doesn't reference the list item properly and I don't see how to access a specific item in a list when I have a variable ("num"). Is there a way to do this?

I tried using slice, but looking at SliceFilter::doFilter() it seems like it only works on lists of strings. Is that correct?

Any suggestions on how to approach this?

(Also posted on StackOverflow, but no grantlee tag, so I'm guessing not too many people are using it over there.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant