Setting up a Django admin template

I would like to change the admin template in Django.

 % cat /Library/Python/2.5/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html 
<fieldset class="module aligned {{ fieldset.classes }}">
  {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
  {% if fieldset.description %}<div class="description">{{ fieldset.description|safe }}</div>{% endif %}
  {% for line in fieldset %}
      <div class="form-row{% if line.errors %} errors{% endif %} {% for field in line %}{{ field.field.name }} {% endfor %} ">
      {{ line.errors }}
      {% for field in line %}
      <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
          {% if field.is_checkbox %}
              {{ field.field }}{{ field.label_tag }}
          {% else %}
              {{ field.label_tag }}{{ field.field }}
          {% endif %}
          {% if field.field.field.help_text %}<p class="help">{{ field.field.field.help_text|safe }}</p>{% endif %}
      </div>
      {% endfor %}
      </div>
  {% endfor %}
</fieldset>

What kind of object is a field, or rather, how to get the name of the field?

+3
source share
3 answers

fieldis an instance AdminFieldand field.fieldis an instance BoundField, so you can refer to the field name:

{{ field.field.name }}

As soon as you begin to delve deeply into admin settings, its only place in the documentation is really missing. that, as they say, the code is well written and easy to understand if you spend time researching it, IMHO.

There are not many files to spend the evening reading them. In your case, I would start with:

+3
source

?

python, . ,

    , , . EmailField .

+1

check here if you need to override it at all. a lot is customizable.

By the way, I would like to give you advice: do not overwrite / modify what you do not understand. make yourself understand it first

+1
source

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


All Articles