Thanks Tom it worked! :)

On Wednesday, November 20, 2013 12:18:23 PM UTC+1, Pepsodent Cola wrote:
>
> How can I forloop this count() in my template code?
>
> * I have attached my project files that you might run and see for 
> yourselves.
> * I have attached a screenshot of the table I'm working on.
> * User/Pass = joe/joe
>
>
> def index(request):
>     publications = Publication.objects.all()
>     articles = Article.objects.all()
>
> *    sum_publications = Publication.objects.filter(article__pk=1).count()*
>
>     context = {'publications':publications, 'articles':articles, 
> 'sum_publications':sum_publications}
>     return render(request, 'magazine/index.html', context)
>
>
>
> <article>
>     <h1>How many Publications was each Article in?</h1>
>
> {% if articles %}
>     <table border="1">
>     <tr>
>         <th>Article id</th>
>         <th>Article</th>
>         <th>Publication</th>
>     </tr>
>     {% for row in articles %}
>     <tr>
>         <td>{{ row.id }}</td>
>         <td>{{ row.headline }}</td>
>         <td>*total*</td>
>     </tr>
>     {% endfor %}
>     </table>
> {% else %}
>     <p>No Articles are available.</p>
> {% endif %}
>
>
> *<!-- TypeError: 'int' object is not iterable -->*
> {% if 666sum_publications %}
>     <ul>
>     {% for row in sum_publications %}
>         <li>{{ row }}</li>
>     {% endfor %}
>     </ul>
> {% else %}
>     <p>No sums are available.</p>
> {% endif %}
>
>     <hr>
> </article>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a99dfe0-15af-48e2-ae32-498dcf782d6c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to