Monday, March 23, 2015

Ho to "create" a field in a queryset to show in my template?

Hello,

I have these view:

def planos_view(request, cat_id=0):
if cat_id == '0':
categorias = Categoria.objects.filter(publicado=True)
else:
categorias = Categoria.objects.filter(publicado=True).filter(id=cat_id)

for c in categorias:
c.total = Plano.objects.filter(categoria=c).count()

return render_to_response('planos.html', locals(),
context_instance=RequestContext(request))
I want to add the "total" field in my "categories" model.. What's the best approach for these, because these code above don't work...

Thanks agains 

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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+unsubscribe@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/CAF1jwZGvrVY2PG8YCgR3r4LS8URaR6-V2rP_EW3j9RJMpkVr3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment