1
votes

I defined a custom comment form in forms.py as fallow

class CommentFormWithReply(CommentForm):
    reply_to = forms.ModelChoiceField(queryset=CommentWithReply.objects.all(),
            widget=forms.HiddenInput(), required=False)

    def get_comment_model(self):
        # Use our custom comment model instead of the built-in one.
        return CommentWithReply

    def get_comment_create_data(self):
        # Use the data of the superclass, and add in the title field
        data = super(CommentFormWithReply, self).get_comment_create_data()
        return data

what should I do to render this form with the current user information as default values (name, email, webpage ).

1

1 Answers

1
votes

may be this:

https://docs.djangoproject.com/en/dev/ref/forms/fields/#initial

if request.method == 'POST':
    form = CommentFormWithReply(request.POST)
    .........................................


if request.method == 'GET':
    default_data = {'name': 'Alexey', 'email': '[email protected]', 'webpage': 'http://example.com'}
    form = CommentFormWithReply(default_data)