#32354: HTML in verbose_name
--------------------------------------+------------------------
Reporter: serl | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
Hello,
I'm having some issues with the `verbose_name` of some of the fields in my
models.
In particular, I'd like to put some HTML in there. Here's an example:
{{{#!python
short_ohohoh = models.CharField(
mark_safe("<abbr title='This is way longer'>Short</abbr> ohohoh"),
max_length=100,
)
}}}
The problem is: even if I `mark_safe`, the verbose_name is escaped when I
try to get it in my templates with: `{{ form.short_ohohoh.label }}` or `{{
form.short_ohohoh.label_tag }}`.
----
I dug in Django's code, and I found out that the verbose_name passes
through a `capfirst` here in `formfield`:
https://github.com/django/django/blob/75182a800a621b7a5b2c0a1f39a56e753b9a58ca/django/db/models/fields/__init__.py#L916.
That way, my SafeString is transformed back to str, I guess. I tried to
remove the `capfirst` and assigning directly `verbose_name` and my HTML is
preserved (but fields without `verbose_name` are, obviously, lowercase).
As a workaround, in my templates, I can `mark_safe` it again, but sadly
the Django admin displays my fields incorrectly.
----
So yeah, for starters: is there a better way to deal with acronymns in my
models?
Then, I would move the `capfirst` directly to `set_attributes_from_name`
in
https://github.com/django/django/blob/75182a800a621b7a5b2c0a1f39a56e753b9a58ca/django/db/models/fields/__init__.py#L772.
Is there a reason why it is not already there?
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/32354>
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/047.195194e0674c1f9c142d4c0498f40744%40djangoproject.com.