Anil
Anil

Reputation: 21

django form subclass for comments

hello im trying to subclass the CommentForm, and I'm not sure if I'm doing it correctly. I'm making those fields hidden, but they aren't rendering that way.

from django.contrib.comments.forms import CommentForm
from django import forms
from django.utils.translation import ungettext, ugettext_lazy as _

class customCommentForm(CommentForm):
    name          = forms.CharField(widget=forms.HiddenInput)
    email         = forms.EmailField(widget=forms.HiddenInput)
    url           = forms.URLField(widget=forms.HiddenInput)
    comment       = forms.CharField(label=_('Comment'), widget=forms.Textarea,
                                  max_length=3000)

Upvotes: 2

Views: 169

Answers (1)

Tom Belote
Tom Belote

Reputation: 590

It is a bit of a hack, but I ending up doing this in the template with something like

        {% ifequal field.name "name" %} style="display:none;"{% endifequal %}
        {% ifequal field.name "email" %} style="display:none;"{% endifequal %}
        {% ifequal field.name "url" %} style="display:none;"{% endifequal %}
        {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>

Upvotes: 1

Related Questions