开发者

Django forms: Changing help_text dynamically

开发者 https://www.devze.com 2023-01-08 04:41 出处:网络
Is this even possible? So let\'s say that I have two forms, one inherits from the other because they have similar fields with the same validation.But the only d开发者_如何学Goifference is they have d

Is this even possible?

So let's say that I have two forms, one inherits from the other because they have similar fields with the same validation. But the only d开发者_如何学Goifference is they have different help text. How could I have two different help text on these forms?


Try this:

class A(Form):
  f = CharField(help_text='sth')


class B(A):

    def __init__(self, *args, **kwargs):
        super(B, self).__init__(*args, **kwargs)
        self.fields['f'].help_text = 'changed'
0

精彩评论

暂无评论...
验证码 换一张
取 消