Berislav Lopac
Berislav Lopac

Reputation: 17253

Displaying model's docstring in admin app

In Django admin, help_text attribute for individual fields is displayed to give instructions. However, I would like to include a similar feature for the whole models.

In the code, I'm using docstrings to keep general instructions about models, and it would be very useful if I could display it in the Django admin. The perfect way would be to use the first line of a model's docstring on the index pages, and the whole contents on the list and form pages.

Are there any modules/snippets solving that, or should I simply write my own? ;.)

Upvotes: 4

Views: 1553

Answers (1)

jpic
jpic

Reputation: 33420

Not the "perfect way" you described, but there is django.contrib.admindocs

For the "perfect way", you could make a little template filter that returns the docstring of a model, and use that in your overloads or admin/change_form.html and admin/change_list.html.

Correct me if I'm wrong but docstrings are not the perfect place for contents that should be localized.

If you have a rather short amount of text per model to localize, like one or two sentences, here's a few thoughts:

  • A short amount of text can be held in a python variable.
  • A Python variable can be proxied by django.utils.translation.ugettext.
  • A class can hold a python variable.

So I'd try something like:

from django.utils.translation import ugettext as _

class Foo(models.Model):
    help_text = _(u'Documentation of Foo model to localize')

Upvotes: 2

Related Questions