Display docstring model in admin application

The Django administrator displays the help_text attribute for individual fields to indicate instructions. However, I would like to enable a similar feature for all models.

In the code, I use docstrings to store general instructions about models, and it would be very useful if I could display it in the Django admin. The ideal way is to use the first line of the docstring model on the index pages and all the content on the list and form pages.

Are there any modules / snippets that solve this, or should I just write my own?;.)

+4
source share
1 answer

Not the โ€œperfect wayโ€ you described, but django.contrib.admindocs

For the โ€œperfect wayโ€, you can create a small template filter that returns the docstring of the model, and use this in your overloads, either admin / change_form.html and admin / change_list.html.

Correct me if I am wrong, but docstrings are not the perfect place for content to be localized.

If you have a small amount of text for each model for localization, for example, one or two sentences, here are a few considerations:

  • A small portion of the text can be stored in a python variable.
  • Python variable can be proxied by django.utils.translation.ugettext.
  • The class may contain a python variable.

So, I would try something like:

 from django.utils.translation import ugettext as _ class Foo(models.Model): help_text = _(u'Documentation of Foo model to localize') 
+2
source

Source: https://habr.com/ru/post/1399734/


All Articles