Opened 8 years ago
Closed 8 years ago
#27296 closed New feature (needsinfo)
Can't use custom formats with new language-independent LogEntry's messages in Django 1.10
Reported by: | Ivan Tsouvarev | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Say, you have some model, which __str__
uses django.utils.formats.date_format
with custom format string.
settings.FORMAT_MODULE_PATH
contains module, in which this string is defined.
So, when you create object of this model via admin interface, the following things happen:
- Django calls
construct_change_message
to create LogEntry, which is decorated with@translation_override(None)
, which will deactivate current language - To write object representation with custom format in change message,
django.utils.formats.get_format
will be called get_format
will try to find custom format, but it can't be done when active language is None, so original string will be returned as-isdjango.utils.dateformat.format
will interpret custom format string literally, which may not fail with exception, but will be totally wrong anyway
Change History (4)
comment:1 by , 8 years ago
Component: | Uncategorized → contrib.admin |
---|
comment:2 by , 8 years ago
Hard to say. May be there is a way to avoid translation without deactivating current language?
comment:3 by , 8 years ago
I don't see a proper solution yet, apart from providing some default yourself by comparing the get_format
return value.
comment:4 by , 8 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Type: | Uncategorized → New feature |
Feel free to reopen if someone thinks of a proposal of how Django could facilitate this use case.
Do you have any suggestions about how to fix that?