Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd comment count near the link Django
    text
    copied!<p>I have a working blog. Each post has a link "Comments" that leads to comments for that particular post. I want to add comment count so it would look like: "Comments (5)" ect.</p> <p>I added <code>% get_comment_count for post.pk as comment_count %}</code> value to my template, so it looks like this :</p> <pre><code> {% for post in posts.object_list %} &lt;div class="post"&gt; &lt;div class="title"&gt;{{ post.title }}&lt;/div&gt; &lt;ul&gt; &lt;div class="time"&gt;{{ post.created }}&lt;/div&gt; &lt;div class="body tresc"&gt;{{ post.body }}&lt;/div&gt; {% get_comment_count for post.pk as comment_count %} &lt;div class="commentlink"&gt;&lt;a href="post/{{ post.pk }}/"&gt;{{ comment_count }} Comments&lt;/a&gt;&lt;/div&gt; &lt;/ul&gt; &lt;/div&gt; {% endfor %} </code></pre> <p>but I get the error :</p> <pre><code>Invalid block tag: 'get_comment_count', expected 'empty' or 'endfor' </code></pre> <p>at line containing <code>{% get_comment_count for post.pk as comment_count %}</code>. What am I doing wrong?</p> <p>My models.py looks like that :</p> <pre><code>from django.db import models from django.contrib import admin class Post(models.Model): title = models.CharField(max_length=60) body = models.TextField() created = models.DateTimeField(auto_now_add=True) def __unicode__(self): return self.title class PostAdmin(admin.ModelAdmin): search_fields = ["title"] class Comment(models.Model): created = models.DateTimeField(auto_now_add=True) author = models.CharField(max_length=60) body = models.TextField() post = models.ForeignKey(Post) def __unicode__(self): return unicode("%s: %s" % (self.post, self.body[:60])) class CommentAdmin(admin.ModelAdmin): display_fields = ["post", "author", "created"] admin.site.register(Comment, CommentAdmin) admin.site.register(Post, PostAdmin) </code></pre> <p>How can I use db_table to change the table Django is reading comments from? I need it to read from <code>news_comment</code> table.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload