Django(1.2)表单:ManyToManyField Help Tex

2024-04-25 08:20:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望我错了,但在我看来,要想使一个many域没有help_text的唯一方法是为表单编写一个__init__方法,然后重写self.fields[fieldname].help_text。这真的是唯一的办法吗?我更喜欢使用CheckboxSelectMultple小部件,那么我真的要为任何使用ManyToManyField的表单定义__init__方法吗?在

class ManyToManyField(RelatedField, Field):
    description = _("Many-to-many relationship")
    def __init__(self, to, **kwargs):
        #some other stuff
        msg = _('Hold down "Control", or "Command" on a Mac, to select more than one.')
        self.help_text = string_concat(self.help_text, ' ', msg)

Tags: to方法textself表单fieldsinit部件
3条回答

你没有错。我自己也遇到了这个问题,为了避开这个问题,我创建了自己的ManyToManyField。在

下面是我评论的一个相关错误:http://code.djangoproject.com/ticket/6183

以常规形式:

MyForm.base_fields['many_to_many_field'].help_text = ''

如果要更改(i18n)字符串:

^{pr2}$

用django 1.6测试

class Item(models.Model):
    ...
    category = models.ManyToManyField(Category, null=True,blank=True)
    category.help_text = ''
    ...

相关问题 更多 >