humanize.txt 2.4 KB

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