Resize fields in Django Admin

后端 未结 14 2006
一生所求
一生所求 2020-12-22 15:12

Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 chara

14条回答
  •  生来不讨喜
    2020-12-22 15:32

    A quick and dirty option is to simply provide a custom template for the model in question.

    If you create a template named admin///change_form.html then the admin will use that template instead of the default. That is, if you've got a model named Person in an app named people, you'd create a template named admin/people/person/change_form.html.

    All the admin templates have an extrahead block you can override to place stuff in the , and the final piece of the puzzle is the fact that every field has an HTML id of id_.

    So, you could put something like the following in your template:

    {% extends "admin/change_form.html" %}
    
    {% block extrahead %}
      {{ block.super }}
      
    {% endblock %}
    

提交回复
热议问题