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

前端 未结 6 2009
抹茶落季
抹茶落季 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条回答
  •  清酒与你
    2020-12-22 23:11

    Use the admin's fieldsets:

    class MyAdmin(admin.ModelAdmin):
        fieldsets = (
            (None, {
                'fields': ('first', 'second', 'etc'),
                'description': "This is a set of fields group into a fieldset."
            }),
        )
        # Other admin settings go here...
    

    You can have multiple fieldsets in an admin. Each can have its own title (replace the None above with the title). You can also add 'classes': ('collapse',), to a fieldset to have it start out collapsed (the wide class makes the data fields wider, and other class names mean whatever your CSS says they do).

    Be careful: the description string is considered safe, so don't put any uncleaned data in there. This is done so you can put markup in there as needed (like your link), however, block formatting (like

      lists) will probably look wrong.

提交回复
热议问题