I had created a comment app with custom field like “parentId” and “email_notification”.
In the template, the comments tag can pull out items I add, but the “get_comment_form” tag does not show a form. Also, how do I customize the fields in that form?
models.py
from django.db import models
from django.contrib.comments.models import Comment
class CommentWithParent(Comment):
parentId = models.IntegerField(default = 0)
email_notification = models.BooleanField(default = False)
forms.py
from django import forms
from django.contrib.comments.forms import CommentForm
from mblog.my_comment.models import CommentWithParent
from django.db import models
class CommentWithParentForm(CommentForm):
parentId = models.IntegerField(default = 0)
email_notification = models.BooleanField(default = False)
def get_comment_model(self):
return CommentWithParent
def get_comment_create_data(self):
data = super(CommentWithParentForm, self).get_comment_create_data()
return data
def get_form(self):
return self
template file
{% load comments %}
{% get_comment_form for entry as form %}
You can learn more about customizing the form template in the documentation. In general terms, you can hide some fields from the form or control which form widgets are used to display them. To change how they look, you’ll want to use the application’s CSS, or create a new template as the documentation describes.
I’m not entirely sure why the
get_comment_formtag isn’t working for you. The documentation linked above suggests you need a form in your view which the template can then render using a different tag; here’s that section of the documentation. If you’re not using Django 1.4, things might be slightly different.