django.contrib.comments and multiple comment forms -
i followed guide @ https://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/ set comment form on news entries current django app. now, need have comment form different fields type of object in part of site.
how should accomplised considering i've overridden contact form already?
that's question; django seem pretty insistent use same comment form everywhere. can write single form shows different fields based on object it's instantiated with. try writing init method along lines of this:
class customcommentform(commentform): custom_field = forms.charfield(max_length=100) def __init__(self, *args, **kwargs): super(customcommentform, self).__init__(*args, **kwargs) # check what's in kwargs['initial'], , insert fields if needed this: if ...: self.fields['optional_field'] = forms.charfield(max_length=100)
Comments
Post a Comment