Code

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#14355 closed (fixed)

"readonly" fields don't display their "help_text" in admin

Reported by: jester Owned by: wamberg
Component: contrib.admin Version: 1.2
Severity: Keywords: readonly help_text
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Steps to reproduce

  1. Define a Model, whose field(s) specify help_text, e.g.:
class MyModel(Model):
    my_regular_field = CharField(max_length=255, help_text="this is my regular field")
    my_readonly_field = CharField(max_length=255, help_text="this is my readonly field")
  1. Define a ModelAdmin for your Model, including one of its fields in readonly_fields, e.g.:
class MyModelAdmin(ModelAdmin):
    fields = 'my_regular_field', 'my_readonly_field'
    readonly_fields = 'my_readonly_field',
admin.site.register(MyModel, MyModelAdmin)

In the object view/edit screen, "My regular field" will have help text, "My readonly field" will not.

Expectation

The expected behavior is that readonly fields will work just like "regular" fields, except their widget will be their plain value rather than a form element -- i.e., any string specified as "help_text" should be displayed after the field.

Uneducated guesswork

I don't dig very deep into the workings of the admin very often, and so, obviously, what I'm about to say may be entirely unhelpful. However, it appears that helpers.AdminReadonlyField constructs a limited, faux field object, a dict, at self.field, rather than assign the appropriate BoundField instance. This is perhaps because readonly fields are not available to it in self.form.fields. In the template, field.field.field.help_text fails, as the dict does not contain "help_text", (and I'm not sure where AdminReadonlyField would get it, anyway).

Attachments (6)

patch.diff (3.4 KB) - added by alexbmeng@… 4 years ago.
Added help_text to readonly admin fields
patch.2.diff (3.2 KB) - added by subsume 4 years ago.
removed exception
patch.3.diff (3.2 KB) - added by subsume 4 years ago.
removed exception
patch.4.diff (2.8 KB) - added by subsume 4 years ago.
removed exception
patch.5.with_test.diff (4.1 KB) - added by wamberg 3 years ago.
git diff patch for help_text on readonly fields
14355_readonly_fields_help_text.diff (4.3 KB) - added by julien 3 years ago.

Download all attachments as: .zip

Change History (15)

Changed 4 years ago by alexbmeng@…

Added help_text to readonly admin fields

comment:1 Changed 4 years ago by anonymous

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 4 years ago by subsume

removed exception

Changed 4 years ago by subsume

removed exception

Changed 4 years ago by subsume

removed exception

comment:2 Changed 3 years ago by nessita

  • Owner changed from nobody to nessita

comment:3 Changed 3 years ago by nessita

  • milestone set to 1.3
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

I confirmed that the help text is not being shown in the admin add/change form, for a read only field.

The patch attached by the reporter does not include tests for this fix, so I'm setting this bug properties accordingly.

comment:4 Changed 3 years ago by nessita

  • Owner changed from nessita to nobody

comment:5 Changed 3 years ago by wamberg

  • Owner changed from nobody to wamberg
  • Status changed from new to assigned

Changed 3 years ago by wamberg

git diff patch for help_text on readonly fields

Changed 3 years ago by julien

comment:6 Changed 3 years ago by julien

  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

Thank you alexbmeng, subsume and wamberg. Your latest patch looked good. I've just removed a line (self.help_text = ...) which was unnecessary and wrote some slightly more thorough tests. I believe this is RFC now.

comment:7 Changed 3 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

In [15582]:

Fixed #14355 -- Ensure that help_text is displayed for readonly fields in the admin. Thanks to jester for the report, and to alexbmeng, subsume, wamberg and Julien Phalip for ther work on the patch.

comment:8 Changed 3 years ago by russellm

In [15583]:

[1.2.X] Fixed #14355 -- Ensure that help_text is displayed for readonly fields in the admin. Thanks to jester for the report, and to alexbmeng, subsume, wamberg and Julien Phalip for ther work on the patch.

Backport of r15582 from trunk.

comment:9 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.