@James Now I understand what you mean. :) I will work on this some more tonight.
On Wednesday, November 20, 2013 10:29:24 PM UTC+1, Pepsodent Cola wrote: > > 1.) > How do I use mathematical calculations on my forloop Article/Publication > list? > > * I have attached a screenshot with the table field that I'm working on > *"Publicists > coverage (%)"*. > * Admin user/pass = joe/joe > * I have also attached my project files so that you can see things for > yourselves. > > > 2.) > Is the solution I'm working with in "Index View page" the correct practice > to do my mathematical calculations? > > > #_______________________________________________________________________________ > > def index(request): > publications = Publication.objects.all() > > > # sum_publications = Publication.objects.filter(article__pk=1).count() > articles = > Article.objects.all().annotate(num_publications=Count('publications')) > * #articles_int = int(articles)* > > * sum_publicists = Publication.objects.all().count()* > > * #publicists_coverage = articles/sum_publicists* > > > # context = {'publications':publications, > 'sum_publicists':sum_publicists, > # 'publicists_coverage':publicists_coverage, > 'articles':articles} > context = {'publications':publications, > 'sum_publicists':sum_publicists, > 'articles':articles} > 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> > * <th>Publicists coverage (%)</th>* > </tr> > {% for row in articles %} > <tr> > <td>{{ > row.id<http://www.google.com/url?q=http%3A%2F%2Frow.id&sa=D&sntz=1&usg=AFQjCNGG971NtAwWsaCVNskfLhyoY4rmew>}}</td> > <td>{{ row.headline }}</td> > <td>{{ row.num_publications }}</td> > <td>(*{{ row.num_publications }} / {{ sum_publicists }}*) = x > %</td> > </tr> > {% endfor %} > </table> > {% else %} > <p>No Articles are available.</p> > {% endif %} > > <hr> > </article> > > > #_______________________________________________________________________________ > > > 3.) > When I try to convert articles object into int it doesn't work. Am I > going the wrong direction when thinking about solving things like this? > > > Exception Type: TypeError > Exception Value: *int() argument must be a string or a number, not > 'QuerySet'* > Exception Location: /home/linux/Django/ManyToMany/magazine/views.py in > index, line 17 > > > >>> articles = > Article.objects.all().annotate(num_publications=Count('publications')) > >>> type(articles) > <class 'django.db.models.query.QuerySet'> > >>> > >>> *articles_int = int(articles)* > Traceback (most recent call last): > File "<console>", line 1, in <module> > TypeError: int() argument must be a string or a number, not 'QuerySet' > >>> > > > > > > > -- 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/b6c2d614-15a1-4741-a099-64bd4637fa14%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.