0

コメントフォームのコメントフィールドにインラインスタイルを追加するつもりはありません。プレースホルダー属性をフィールドに追加する方法を探しています。これを行うための適切な方法は何ですか?

get_comment_create_dataメソッドのウィジェットを追加/変更する方法を探していました。

これが私の現在のフォームの外観です。

# forms.py
...
class PostComment(CommentForm):
    """
    A lighter comment form.
    """
    def get_comment_create_data(self):
        """
        This needs to be overwritten to remove the fields from the class
        """
        return dict(
            content_type = ContentType.objects.get_for_model(self.target_object),
            object_pk    = force_unicode(self.target_object._get_pk_val()),
            comment      = self.cleaned_data['comment'],
            submit_date  = datetime.datetime.now(),
            site_id      = settings.SITE_ID,
            is_public    = True,
            is_removed   = False,
        )
...
4

1 に答える 1

1

次のようにクラス メソッドを拡張できます。

class PostComment(CommentForm):
    def get_comment_create_date(self):
        data = super(PostComment, self).get_comment_create_data()
        data.update(dict(
            placeholder  = 'foo'
        ))
        return data
于 2012-09-10T06:31:17.460 に答える