Created
March 5, 2012 04:22
-
-
Save rwmyers/1976605 to your computer and use it in GitHub Desktop.
Comment Django Model Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% with total=post.comment_set.all.count %} | |
| <a href="/blog/{{ post.slug }}#comments">{{ total }} Comment{{ total|pluralize }}</a> | |
| {% endwith %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| div.comment | |
| { | |
| background-color: #EAEAEA; | |
| padding: 10px; | |
| margin-bottom: 15px; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| python manage.py syncdb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment