Adding model-wide help text to a django model's admin form

前端 未结 6 1991
抹茶落季
抹茶落季 2020-12-22 23:02

In my django app, I would like to be able to add customized help text to the admin change form for some of my models. Note I\'m not talking about the field specific h

6条回答
  •  Happy的楠姐
    2020-12-22 23:11

    If I understand what you want the code below should do what you want.

    def __init__(self, *args, **kwargs):
            super(ClassName, self).__init__(*args, **kwargs)
            if siteA:
                help_text = "foo"
            else:
                help_text = "bar"
            self.form.fields["field_name"].help_text = help_text
    

    That's an example of using some logic to modify an overriden form. So you just put this in your ModelAdmin constructor that you overrode.

提交回复
热议问题