2008-08-24 06:25:40 +08:00
|
|
|
========================
|
|
|
|
django.contrib.humanize
|
|
|
|
========================
|
|
|
|
|
|
|
|
.. module:: django.contrib.humanize
|
|
|
|
:synopsis: A set of Django template filters useful for adding a "human
|
|
|
|
touch" to data.
|
|
|
|
|
|
|
|
A set of Django template filters useful for adding a "human touch" to data.
|
|
|
|
|
|
|
|
To activate these filters, add ``'django.contrib.humanize'`` to your
|
|
|
|
:setting:`INSTALLED_APPS` setting. Once you've done that, use
|
2010-11-29 13:30:11 +08:00
|
|
|
``{% load humanize %}`` in a template, and you'll have access to the following
|
|
|
|
filters.
|
|
|
|
|
|
|
|
.. templatefilter:: apnumber
|
2008-08-24 06:25:40 +08:00
|
|
|
|
|
|
|
apnumber
|
|
|
|
--------
|
|
|
|
|
|
|
|
For numbers 1-9, returns the number spelled out. Otherwise, returns the
|
|
|
|
number. This follows Associated Press style.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
* ``1`` becomes ``one``.
|
|
|
|
* ``2`` becomes ``two``.
|
2008-08-24 06:25:40 +08:00
|
|
|
* ``10`` becomes ``10``.
|
|
|
|
|
|
|
|
You can pass in either an integer or a string representation of an integer.
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
.. templatefilter:: intcomma
|
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
intcomma
|
|
|
|
--------
|
|
|
|
|
|
|
|
Converts an integer to a string containing commas every three digits.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
* ``4500`` becomes ``4,500``.
|
|
|
|
* ``45000`` becomes ``45,000``.
|
|
|
|
* ``450000`` becomes ``450,000``.
|
|
|
|
* ``4500000`` becomes ``4,500,000``.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
|
|
|
You can pass in either an integer or a string representation of an integer.
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
.. templatefilter:: intword
|
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
intword
|
|
|
|
-------
|
|
|
|
|
|
|
|
Converts a large integer to a friendly text representation. Works best for
|
|
|
|
numbers over 1 million.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
* ``1000000`` becomes ``1.0 million``.
|
|
|
|
* ``1200000`` becomes ``1.2 million``.
|
|
|
|
* ``1200000000`` becomes ``1.2 billion``.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
|
|
|
Values up to 1000000000000000 (one quadrillion) are supported.
|
|
|
|
|
|
|
|
You can pass in either an integer or a string representation of an integer.
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
.. templatefilter:: naturalday
|
2008-08-24 06:25:40 +08:00
|
|
|
|
|
|
|
naturalday
|
|
|
|
----------
|
|
|
|
|
|
|
|
For dates that are the current day or within one day, return "today",
|
|
|
|
"tomorrow" or "yesterday", as appropriate. Otherwise, format the date using
|
|
|
|
the passed in format string.
|
|
|
|
|
2010-11-29 13:30:11 +08:00
|
|
|
**Argument:** Date formatting string as described in the :tfilter:`date` tag.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
|
|
|
Examples (when 'today' is 17 Feb 2007):
|
|
|
|
|
|
|
|
* ``16 Feb 2007`` becomes ``yesterday``.
|
|
|
|
* ``17 Feb 2007`` becomes ``today``.
|
|
|
|
* ``18 Feb 2007`` becomes ``tomorrow``.
|
|
|
|
* Any other day is formatted according to given argument or the
|
|
|
|
:setting:`DATE_FORMAT` setting if no argument is given.
|
2010-11-29 13:30:11 +08:00
|
|
|
|
|
|
|
.. templatefilter:: ordinal
|
|
|
|
|
|
|
|
ordinal
|
|
|
|
-------
|
|
|
|
|
|
|
|
Converts an integer to its ordinal as a string.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
* ``1`` becomes ``1st``.
|
|
|
|
* ``2`` becomes ``2nd``.
|
|
|
|
* ``3`` becomes ``3rd``.
|
|
|
|
|
|
|
|
You can pass in either an integer or a string representation of an integer.
|