How do I override help_text in django's admin interface

django admin help text
django help_text
django admin custom form
django form initial value
django model form

I have multiple admin sites, so different users get a different experience of editing the objects in the database. Each admin site has a different set of objects exposed, and a different styling. All of this can be done by overriding templates and ModelAdmin objects.

I can't work out how to provide different help_text through the different sites. help_text is always taken straight from the model field definition, and there doesn't seem to be a way to override it.

Am I missing something, or is this impossible?

You can create a new model form and override the help_text there:

class MyForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(MyForm, self).__init__(*args, **kwargs)
        self.fields['myfield'].help_text = 'New help text!'

then use the new form in your ModelAdmin:

class MyModel(admin.ModelAdmin):
     ...
     form = MyForm

This is the cleaner way to achieve what you want since form fields belong to forms anyway!

How do I override help_text in django's admin interface, You can create a new model form and override the help_text there: class MyForm​(forms.ModelForm): def __init__(self, *args, **kwargs): super(MyForm, self). Whenever one tries to create an instance of a model either from admin interface or django shell, save() function is run. We can override save function before storing the data in the database to apply some constraint or fill some ready only fields like SlugField.

In Django 1.9, similar to below works for me

def get_form(self, request, obj=None, **kwargs):
    form = super(MyAdmin, self).get_form(request, obj, **kwargs)
    form.base_fields['my_field'].help_text = """
    Some helpful text
    """
    return form

Django hack: Help text on a model instance, If you've been been working with Django for a while, you're probably familiar with the help_text attribute for model fields. It gives us a hook for  Attached an updated version of the patch from #12359 by trey@… which moves the assignment of the help_text from django.db.models.fields.related to django.contrib.admin.options. I had begun making a patch to move the help_text assignment to django.forms.widgets.SelectMultiple, but in doing so I realized that this, too, is poor behavior.

An alternative way is to pass help_texts keyword to the get_form method like so:

def get_form(self, request, obj=None, **kwargs):
    help_texts = {'my_field': 'Field explanation'}
    kwargs.update({'help_texts': help_texts})
    return super(FooAdmin, self).get_form(request, obj, **kwargs)

The help_texts keyword gets eventually passed to the modelform_factory method and rendered as the standard help text from a model in the Django admin.

In case you're using an InlineModelAdmin, you need to override get_formset in the same manner.

This also works if you have readonly_fields in your ModelAdmin subclass.

help_text - Django Built-in Field Validation, Pass in a dictionary with keys matching the error messages you want to override. help_text, Extra “help” text to be displayed with the form widget. It's useful for  Overriding templates¶ In your project, you might want to override a template in another Django application, whether it be a third-party application or a contrib application such as django.contrib.admin. You can either put template overrides in your project’s templates directory or in an application’s templates directory.

Cerin is right, but his code does not work well (at least with Django 1.4).

def get_readonly_fields(self, request, obj):
    try:
        field = [f for f in obj._meta.fields if f.name == 'author']
        if len(field) > 0:
            field = field[0]
            field.help_text = 'some special help text'
    except:
        pass
    return self.readonly_fields

You will have to change "author" and the help_text string to fit your needs.

Creating forms from models | Django documentation, you must override the form field to use a different widget. Similarly, you can specify the labels , help_texts and  One of the patterns we get positive feedback for mentioning in our book is overloading form fields. The problem this pattern handles is the use case of when we have a model with a field(s) that allows for blank values, how do we force users to enter values?

You can always change form field attributes on ModelAdmin constructor, something like:

    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

When overriding the widget for a manytomany field default help_text , And it gets rendered as seen in the screen shot. I guess the issue is with line 761 in django.db.models.fields.related msg = ugettext_lazy('Hold down "Control  Django community: Django Q&A RSS This page, updated regularly, aggregates Django Q&A from the Django community. How to temporarily disable a token in Django REST Framework Posted on September 15, 2019 at 7:21 PM by Stack Overflow RSS

Writing custom model fields | Django documentation, that Django records about a field is common to all fields – name, help text, Once you've created your Field subclass, you might consider overriding a few  If you don’t specify primary_key=True for any field in your model, Django will automatically add an AutoField to hold the primary key, so you don’t need to set primary_key=True on any of your fields unless you want to override the default primary-key behavior.

Can't see admin add-another + button when overriding a , Model field's help_text and verbose_name are lost when overriding the widget¶. This has nothing to do with django-autocomplete-light, but still it's a FAQ so here​  I'm in the process of moving a rather large router configuration parser from a nighly cron job to a series of celery tasks ~18000 scheduled through celery beat as part of a Django application.

Overloading Django Form Fields, It can also be applied to help_text , label , choices , widgets , or any other form field attribute: from django import forms from .models import  I'm pretty new to Django. I have written a text analysis program which I recently managed to deploy online. The program takes a text input and counts the occurrence of words in the input on a corresponding list, and then returns a score on several different variables.

Comments
  • Oddly, this doesn't seem to work with editable=False fields. These don't even appear in form.fields...
  • Hello @Cerin, yes you're right, read only fields are always excluded from the admin model forms. They are not readonly/disabled form inputs or something like that, it's just the str repr of the model field or method.
  • This is an useful and quick way to do it!
  • Doesn't work as far as I can see - ModelAdmin.fields is just a list of strings: docs.djangoproject.com/en/dev/ref/contrib/admin/…
  • Oops! Actually, fields will be available through the form attribute of ModelAdmin. Also, make sure parent constructor is called first. See edit.
  • Still doesn't work for me: "type object 'ModelForm' has no attribute 'fields'"
  • I am getting the same error as well. Did you find a solution to this? I also tried overriding the get_form() method of the ModelAdmin and manipulating the field with no luck.