Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model "help" text in Django Inline Admin

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,)
like image 384
hordur Avatar asked Mar 23 '13 18:03

hordur


Video Answer


2 Answers

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

like image 198
Glyn Jackson Avatar answered Sep 28 '22 06:09

Glyn Jackson


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).

like image 43
ecp Avatar answered Sep 28 '22 07:09

ecp