Skip to content

Instantly share code, notes, and snippets.

@rwmyers
Created March 5, 2012 04:22
Show Gist options
  • Select an option

  • Save rwmyers/1976605 to your computer and use it in GitHub Desktop.

Select an option

Save rwmyers/1976605 to your computer and use it in GitHub Desktop.
Comment Django Model Object
{% with total=post.comment_set.all.count %}
<a href="/blog/{{ post.slug }}#comments">{{ total }} Comment{{ total|pluralize }}</a>
{% endwith %}
class Comment(models.Model):
post = models.ForeignKey(Post)
username = models.CharField(max_length=50)
user_url = models.URLField()
body = models.TextField()
posted = models.DateTimeField(auto_now=True)
def __unicode__(self):
return 'Post by %(username)s on %(posted)s' %\
{ "username" : self.username, "posted": self.posted }
<div class="comments">
<a name="comments" />
<h3>Comments</h3>
{% for comment in post.comment_set.all %}
<div class="comment">
<div class="body">
{{ comment.body }}
</div>
<div class="author">
<a href="{{ comment.user_url }}">{{ comment.username }}</a> on {{ comment.posted }}
</div>
</div>
{% endfor %}
</div>
div.comment
{
background-color: #EAEAEA;
padding: 10px;
margin-bottom: 15px;
}
python manage.py syncdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment