Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add `help_text` to Django Admin field

I'm attempting to display an image when editing a user on the admin panel, but I can't figure out how to add help text.

I'm using this Django Admin Show Image from Imagefield code, which works fine.

However the short_description attribute only names the image, and help_text doesn't seem to add an text below it.

How can I add help_text to this field like normal model fields?

EDIT:

I would like to have help_text on the image like the password field does in this screenshot:

screenshot of admin page

like image 752
cdignam Avatar asked Aug 06 '17 18:08

cdignam


People also ask

What is Fieldsets in Django admin?

fieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a “section” of the form.)

Can Django admin be used in production?

Django's Admin is amazing. A built-in and fully functional interface that quickly gets in and allows data entry is priceless. Developers can focus on building additional functionality instead of creating dummy interfaces to interact with the database.


1 Answers

Use a custom form if you don't want change a model:

from django import forms

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

    class Meta:
        model = MyModel
        exclude = ()

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    form = MyForm
    # ...
like image 122
Anton Shurashov Avatar answered Oct 04 '22 23:10

Anton Shurashov