11

I'm using an inline admin in my Django application. I want to have some help text displayed in the admin form for Page to go with the inline admin (not just the individual help text for each field within that model). I've been trying to figure out how to do this, but cannot seem to find anything on the issue. Am I missing some trivial out-of-the box option for doing this?

If there's no super simple way to do this, is there a way to do this by extending some template?

Below are parts of my models and their admins:

class Page(models.Model):
    ....

class File(models.Model):
    page = models.ForeignKey(Page)
    ....

class FileAdminInline(admin.TabularInline):
    model = File
    extra = 0

class PageAdmin(admin.ModelAdmin):
    inlines = (FileAdminInline,)
hordur
  • 111
  • 1
  • 3
  • Possible duplicate of [Adding model-wide help text to a django model's admin form](http://stackoverflow.com/questions/3728617/adding-model-wide-help-text-to-a-django-models-admin-form) – Antonis Christofides Sep 06 '16 at 11:53

2 Answers2

4

If you're not talking about specific help_text attribute then then look at this post it shows an underdocumented way of accomplishing this.

tim-mccurrach
  • 6,395
  • 4
  • 23
  • 41
Glyn Jackson
  • 8,228
  • 4
  • 29
  • 52
  • I do not see how this helps with __Inline__ Admins. The accepted answer's `render_change_form` does not apply to Inlines and the answer with the most votes talks about fieldsets, which are not helpful for a general Inline help text either. – vlz Nov 01 '22 at 15:05
2

If you don't want to mess around with getting the help_text information into the formset's context and modify the edit_inline template, there is a way of capturing the verbose_name_plural Meta attribute of your model for that purpose.

Basic idea: If you mark that string as safe you can insert any html element that comes to your mind. For example an image element with it's title set to global your model help text. This could look somethink like this:

class Meta:
    verbose_name = "Ygritte"
    verbose_name_plural = mark_safe('Ygrittes <img src="' + settings.STATIC_URL + \
                                    'admin/img/icon-unknown.svg" class="help help-tooltip" '
                                    'width="15" height="15" '
                                    'title="You know nothing, Jon Snow"/>')

Of course - this is kind of hacky - but this works quite simple, if your model is only accessed as an inline model and you don't need the plural verbose name for other things (e.g. like in the list of models in your application's admin overview).

ecp
  • 2,199
  • 1
  • 12
  • 11
  • If you only want to modify this for your admin pages, `verbose_name_plural` can also be declared as an attribute directly on your `TabularInline` or `InlineModelAdmin` object. See `InlineModelAdmin`: https://github.com/django/django/blob/main/django/contrib/admin/options.py – whp May 19 '23 at 23:44