I am new to django and created a simple blog app and now try to add markdown to the comments:
Here is the model for comment:
class Comment(models.Model):
created = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=60)
body = models.TextField()
post = models.ForeignKey(Blog)
def __unicode__(self):
return unicode("%s: %s" % (self.post, self.body[:60]))
in the post.html, I have:
<!-- Add Comments -->
{% if user.is_authenticated %}
<div id="addc">Your Comment?</div>
<!-- Comment form -->
<form action="{% url "blog.views.add_comment" post.id %}" method="POST">{% csrf_token %}
<div id="comment-form">
<p>{{ form.body }}</p>
</div>
<div id="submit"><input type="submit" value="Submit"></div>
</form>
{% endif %}
and the views that renders post(and comment):
def post_withslug(request, post_slug):
post = Blog.objects.get(slug = post_slug)
comments = Comment.objects.filter(post=post)
d = dict(post=post, comments=comments, form=CommentForm(), user=request.user)
d.update(csrf(request))
return render_to_response("blog/post.html", d)
in form.py I have:
from django_markdown.widgets import MarkdownWidget
class CommentForm(forms.ModelForm):
body = forms.CharField(widget=MarkdownWidget())
class Meta:
model= Comment
fields= ('body',)
I have used django-markdown for admin backend and it works fine there however I'm not sure how to apply this app (or something else to the same effect) to the blog comments and I could not find any tutorial about it. So I appreciate your help.