#28340 closed Cleanup/optimization (wontfix)
USE_THOUSAND_SEPARATOR=True causes primary key to include commas
| Reported by: | Zach Borboa | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| 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
When USE_THOUSAND_SEPARATOR=True, an object's primary key (pk) and identifier (id) fields unexpectedly include commas when used in templates.
Example:
Say I include <input name="article_id" value="{{ obj.pk }}"> in a template with a submit button to save an article, saves will eventually fail QuerySet.get(pk='1,000') containing a comma. Using {{ object.pk }} in a template will initially work, but later fail when the 1000th entry is saved.
Possible solution: Display numbers using a thousand separator when USE_THOUSAND_SEPARATOR=True, except for an object's pk and object's id fields as these are understood to be keys and identifiers, respectively.
Change History (2)
comment:1 by , 8 years ago
| Component: | Uncategorized → Template system |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
| Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 8 years ago
Can this behavior be documented with a note?
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
index 70402b1fc4..c5d83c38a8 100644
--- a/docs/ref/settings.txt
+++ b/docs/ref/settings.txt
@@ -2669,6 +2669,12 @@ format, it will have higher precedence and will be applied instead.
See also :setting:`DECIMAL_SEPARATOR`, :setting:`NUMBER_GROUPING` and
:setting:`THOUSAND_SEPARATOR`.
+.. note::
+
+ Using ``{{ object.pk }}`` and ``{{ object.id }}`` may include
+ :setting:`THOUSAND_SEPARATOR`. Consider using {{ object.pk|unlocalize }}
+ instead.
+
.. setting:: USE_TZ
``USE_TZ``
Use the unlocalize template filter, e.g.
{% load l10n %} {{ obj.pk|unlocalize }}. I don't think some automatic behavior would be desirable considering there could be cases where you want a localized value.