~ubuntu-branches/ubuntu/jaunty/python-django/jaunty

« back to all changes in this revision

Viewing changes to docs/ref/contrib/humanize.txt

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.. _ref-contrib-humanize:
 
2
 
 
3
========================
 
4
django.contrib.humanize
 
5
========================
 
6
 
 
7
.. module:: django.contrib.humanize
 
8
   :synopsis: A set of Django template filters useful for adding a "human
 
9
              touch" to data.
 
10
 
 
11
A set of Django template filters useful for adding a "human touch" to data.
 
12
 
 
13
To activate these filters, add ``'django.contrib.humanize'`` to your
 
14
:setting:`INSTALLED_APPS` setting. Once you've done that, use
 
15
``{% load humanize %}`` in a template, and you'll have access to these filters:
 
16
 
 
17
apnumber
 
18
--------
 
19
 
 
20
For numbers 1-9, returns the number spelled out. Otherwise, returns the
 
21
number. This follows Associated Press style.
 
22
 
 
23
Examples:
 
24
 
 
25
    * ``1`` becomes ``'one'``.
 
26
    * ``2`` becomes ``'two'``.
 
27
    * ``10`` becomes ``10``.
 
28
 
 
29
You can pass in either an integer or a string representation of an integer.
 
30
 
 
31
intcomma
 
32
--------
 
33
 
 
34
Converts an integer to a string containing commas every three digits.
 
35
 
 
36
Examples:
 
37
 
 
38
    * ``4500`` becomes ``'4,500'``.
 
39
    * ``45000`` becomes ``'45,000'``.
 
40
    * ``450000`` becomes ``'450,000'``.
 
41
    * ``4500000`` becomes ``'4,500,000'``.
 
42
 
 
43
You can pass in either an integer or a string representation of an integer.
 
44
 
 
45
intword
 
46
-------
 
47
 
 
48
Converts a large integer to a friendly text representation. Works best for
 
49
numbers over 1 million.
 
50
 
 
51
Examples:
 
52
 
 
53
    * ``1000000`` becomes ``'1.0 million'``.
 
54
    * ``1200000`` becomes ``'1.2 million'``.
 
55
    * ``1200000000`` becomes ``'1.2 billion'``.
 
56
 
 
57
Values up to 1000000000000000 (one quadrillion) are supported.
 
58
 
 
59
You can pass in either an integer or a string representation of an integer.
 
60
 
 
61
ordinal
 
62
-------
 
63
 
 
64
Converts an integer to its ordinal as a string.
 
65
 
 
66
Examples:
 
67
 
 
68
    * ``1`` becomes ``'1st'``.
 
69
    * ``2`` becomes ``'2nd'``.
 
70
    * ``3`` becomes ``'3rd'``.
 
71
 
 
72
You can pass in either an integer or a string representation of an integer.
 
73
 
 
74
naturalday
 
75
----------
 
76
 
 
77
.. versionadded:: 1.0
 
78
 
 
79
For dates that are the current day or within one day, return "today",
 
80
"tomorrow" or "yesterday", as appropriate. Otherwise, format the date using
 
81
the passed in format string.
 
82
 
 
83
**Argument:** Date formatting string as described in the :ttag:`now` tag.
 
84
 
 
85
Examples (when 'today' is 17 Feb 2007):
 
86
 
 
87
    * ``16 Feb 2007`` becomes ``yesterday``.
 
88
    * ``17 Feb 2007`` becomes ``today``.
 
89
    * ``18 Feb 2007`` becomes ``tomorrow``.
 
90
    * Any other day is formatted according to given argument or the
 
91
      :setting:`DATE_FORMAT` setting if no argument is given.