#31867: Inconsistency in rendering hidden fields in Django admin
------------------------------------+--------------------------------------
Reporter: Antoine Humbert | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution:
Keywords: admin hidden field | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
------------------------------------+--------------------------------------
Comment (by Antoine Humbert):
To effectively hide fields values, it would be necessary to modify the
django.contrib.admin.helpers.AdminReadonlyField to set the "is_hidden"
property of "field" dictionary, by setting something like this in
constructor :
{{{
self.field = {
'name': class_name,
'label': label,
'help_text': help_text,
'field': field,
}
if field in form.fields:
self.field["is_hidden"] = form.fields[field].widget.is_hidden
}}}
This prevent the values to be shown in the related column. Unfortunately,
the whole field dictionary is displayed at the begining of table row
(where the hidden input widgets would be rendered if user had change
permission). This is the result of mixing dictionary access (for
AdminReadonlyField.field) vs *real* bound field attributes access (for
AdminField.field) in the admin templates.
A solution to prevent the rendering of dictionary at the begining of row,
changing the constructor of AdminReadonlyField with the following works:
{{{
class _FakeField(dict):
def __str__(self):
return ""
self.field = _FakeField(name=class_name, label=label,
help_text=help_text, field=field)
if field in form.fields:
self.field["is_hidden"] = form.fields[field].widget.is_hidden
}}}
Looks like an awefull ack and it may be better to use a simple data-class.
The important thing is that "field.field" in templates must render an
empty string
--
Ticket URL: <https://code.djangoproject.com/ticket/31867#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.184a1afbb9447652efbd59fe7b579f68%40djangoproject.com.