Detail: comments.all (python)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
QUESTION --------------------------------*
¿Es posible, directamente en template, en vez de post.comments.all sacar un post.comments.filter(status=1)|length para que saque el número de posts con status=1 o tendría que hacer un templatetag específico para ello?.

MODELS ----------------------------------*
class Comment(models.Model):
    post = models.ForeignKey(Post, related_name="comments")
    ...
    status =  models.BooleanField(_('Status'), default=True)

VIEWS -----------------------------------*
myposts = mymodels.Post.objects.all().filter(status=1).order_by('-creation_date')
myposts = paginator.page(page)


TEMPLATE --------------------------------*
<a href="/{{post.slug}}.html#comments">
 {{ post.comments.all|length }}
 {{ _('comment') }}
 {{ post.comments.all|length|pluralize:"s" }}
</a>

[raw] - Pasted by: r0sk on python on May 26, 2011