#34383 closed Bug (fixed)
Layout error in Admin when using help_text
Reported by: | Antonio Candido Nazareth junior | Owned by: | Tom Carrick |
---|---|---|---|
Component: | Template system | Version: | 4.2 |
Severity: | Release blocker | Keywords: | help_text |
Cc: | Tom Carrick | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I'm using Django 4.2b1 and found a problem with the Django admin layout when I use the help_text in model admin. The help_text in the Admin form appears on a separate line and breaks the alignment of the fields. This happens in every browser I've tested.
Create a model with two or more fields that have help_text defined with a size larger than the field name. Register this model in admin.py with ModelAdmin and put them on the same line using fieldsets giving name to the line. Access the edit page of this model in Django admin and observe the layout.
Expected result:
The help_text should appear below the corresponding field, without affecting the alignment of the other fields.
Attachments (3)
Change History (14)
by , 21 months ago
comment:1 by , 21 months ago
Description: | modified (diff) |
---|
comment:2 by , 21 months ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Hi, I don't think you've explained the issue in enough detail to confirm a bug in Django. Do you have any custom templates? Please reopen the ticket if you can debug your issue and provide a sample minimal project that reproduces it.
by , 20 months ago
Error breaking line with two or more columns with help_text
comment:3 by , 20 months ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
Steps to reproduce the error:
Create model new:
app.new.models.py
from django.db import models class Favi(models.Model): faviNumero = models.CharField(max_length=20,help_text='Data incluindo o Horário do término da viagem') matricula1 = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem') matricula3 = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem') matricula2 = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem') matricula = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem') objetivo = models.TextField(verbose_name='Objetivo', help_text='DESCRIÇÃO OBJETIVA DO SERVIÇO A SER EXECUTADO') periodoInicio = models.DateTimeField(verbose_name='Início',help_text='Data incluindo o Horário de início da viagem') periodoTermino = models.DateTimeField(verbose_name='Término',help_text='Data incluindo o Horário do término da viagem')
app.new.admin.py
from django.contrib import admin from new.models import Favi # Register your models here. class FilterFaviAdmin(admin.ModelAdmin): fieldsets = [ (None, {'fields':[('faviNumero','matricula1','matricula3'),'objetivo',('periodoInicio','periodoTermino'),('matricula2','matricula',),]}), ] admin.site.register(Favi,FilterFaviAdmin)
Result appears broken layout with help text as image below installed django pre version 4.2b1
comment:4 by , 20 months ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Thanks for details!
Regression in 96a598356a9ea8c2c05b22cadc12e256a3b295fd.
comment:5 by , 20 months ago
I tried to fix this, it's much better (but not perfect, you can see minor issues on the "Change user" view) with the following diff:
-
django/contrib/admin/static/admin/css/forms.css
diff --git a/django/contrib/admin/static/admin/css/forms.css b/django/contrib/admin/static/admin/css/forms.css index 3cd87ef476..e73831a83f 100644
a b form ul.inline li { 72 72 /* ALIGNED FIELDSETS */ 73 73 74 74 .aligned label { 75 display: block;75 display: inline-block; 76 76 padding: 4px 10px 0 0; 77 77 width: 160px; 78 78 word-wrap: break-word; … … form ul.inline li { 114 114 } 115 115 116 116 form .aligned ul { 117 margin-left: 16 0px;117 margin-left: 166px; 118 118 padding-left: 10px; 119 119 } 120 120 … … form .aligned div.radiolist { 127 127 form .aligned p.help, 128 128 form .aligned div.help { 129 129 margin-top: 0; 130 margin-left: 16 0px;130 margin-left: 166px; 131 131 padding-left: 10px; 132 132 } 133 133 … … form .aligned table p { 191 191 } 192 192 193 193 fieldset .fieldBox { 194 float: left;195 194 margin-right: 20px; 196 195 } 197 196 -
django/contrib/admin/static/admin/css/widgets.css
diff --git a/django/contrib/admin/static/admin/css/widgets.css b/django/contrib/admin/static/admin/css/widgets.css index 572dc0a500..c81bcf654d 100644
a b ul.timelist, .timelist li { 578 578 579 579 /* RELATED WIDGET WRAPPER */ 580 580 .related-widget-wrapper { 581 float: left; /* display properly in form rows with multiple fields */582 581 overflow: hidden; /* clear floated contents */ 583 582 } 584 583 -
django/contrib/admin/templates/admin/includes/fieldset.html
diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html index 5953a5ad3d..0d398d1de1 100644
a b 6 6 {% for line in fieldset %} 7 7 <div class="form-row{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}"> 8 8 {% if line.fields|length == 1 %}{{ line.errors }}{% endif %} 9 {% for field in line %} 10 <div{% if not line.fields|length == 1 %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}> 11 {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %} 12 {% if field.is_checkbox %} 13 {{ field.field }}{{ field.label_tag }} 14 {% else %} 15 {{ field.label_tag }} 16 {% if field.is_readonly %} 17 <div class="readonly">{{ field.contents }}</div> 18 {% else %} 19 {{ field.field }} 20 {% endif %} 21 {% endif %} 22 </div> 23 {% if field.field.help_text %} 24 <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}> 25 <div>{{ field.field.help_text|safe }}</div> 26 </div> 27 {% endif %} 28 {% endfor %} 9 <div> 10 {% for field in line %} 11 <div> 12 <div{% if not line.fields|length == 1 %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}> 13 {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %} 14 {% if field.is_checkbox %} 15 {{ field.field }}{{ field.label_tag }} 16 {% else %} 17 {{ field.label_tag }} 18 {% if field.is_readonly %} 19 <div class="readonly">{{ field.contents }}</div> 20 {% else %} 21 {{ field.field }} 22 {% endif %} 23 {% endif %} 24 </div> 25 {% if field.field.help_text %} 26 <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}> 27 <div>{{ field.field.help_text|safe }}</div> 28 </div> 29 {% endif %} 30 </div> 31 {% endfor %} 32 </div> 29 33 </div> 30 34 {% endfor %} 31 35 </fieldset> -
django/contrib/auth/templates/auth/widgets/read_only_password_hash.html
diff --git a/django/contrib/auth/templates/auth/widgets/read_only_password_hash.html b/django/contrib/auth/templates/auth/widgets/read_only_password_hash.html index c73042b18f..447f55a99b 100644
a b 1 < div{% include 'django/forms/widgets/attrs.html' %}>1 <span{% include 'django/forms/widgets/attrs.html' %}> 2 2 {% for entry in summary %} 3 3 <strong>{{ entry.label }}</strong>{% if entry.value %}: <bdi>{{ entry.value }}</bdi>{% endif %} 4 4 {% endfor %} 5 </ div>5 </span>
comment:6 by , 20 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Print erro on Django Version 4.2b1