Структура комментариев Django, установка значений формы по умолчанию - PullRequest
0 голосов
/ 21 сентября 2011

Я определил пользовательскую форму комментария в forms.py как пара

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

что я должен сделать, чтобы отобразить эту форму с информацией о текущем пользователе в качестве значений по умолчанию (имя, адрес электронной почты, веб-страница).

1 Ответ

0 голосов
/ 21 сентября 2011

может быть таким:

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': 'smt@email.smt', 'webpage': 'http://example.com'}
    form = CommentFormWithReply(default_data)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...