Skip to content

Commit

Permalink
Fixed #109 -- Created DATE_FORMAT, DATETIME_FORMAT and TIME_FORMAT se…
Browse files Browse the repository at this point in the history
…ttings.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1115 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Nov 6, 2005
1 parent 7254799 commit d4df074
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
12 changes: 12 additions & 0 deletions django/conf/global_settings.py
Expand Up @@ -154,6 +154,18 @@
# Example: "http://media.lawrence.com" # Example: "http://media.lawrence.com"
MEDIA_URL = '' MEDIA_URL = ''


# Default formatting for date objects. See all available format strings here:
# http://www.djangoproject.com/documentation/templates/#now
DATE_FORMAT = 'N j, Y'

# Default formatting for datetime objects. See all available format strings here:
# http://www.djangoproject.com/documentation/templates/#now
DATETIME_FORMAT = 'N j, Y, P'

# Default formatting for time objects. See all available format strings here:
# http://www.djangoproject.com/documentation/templates/#now
TIME_FORMAT = 'P'

############## ##############
# MIDDLEWARE # # MIDDLEWARE #
############## ##############
Expand Down
12 changes: 7 additions & 5 deletions django/contrib/admin/views/main.py
Expand Up @@ -10,7 +10,7 @@
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
from django.utils.text import capfirst, get_text_list from django.utils.text import capfirst, get_text_list
from django.conf.settings import ADMIN_MEDIA_PREFIX from django.conf.settings import ADMIN_MEDIA_PREFIX, DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT
import operator import operator


# Text to display within changelist table cells if the value is blank. # Text to display within changelist table cells if the value is blank.
Expand Down Expand Up @@ -401,13 +401,15 @@ def change_list(request, app_label, module_name):
result_repr = getattr(result, 'get_%s' % f.name)() result_repr = getattr(result, 'get_%s' % f.name)()
else: else:
result_repr = EMPTY_CHANGELIST_VALUE result_repr = EMPTY_CHANGELIST_VALUE
# Dates are special: They're formatted in a certain way. # Dates and times are special: They're formatted in a certain way.
elif isinstance(f, meta.DateField): elif isinstance(f, meta.DateField) or isinstance(f, meta.TimeField):
if field_val: if field_val:
if isinstance(f, meta.DateTimeField): if isinstance(f, meta.DateTimeField):
result_repr = dateformat.format(field_val, 'N j, Y, P') result_repr = capfirst(dateformat.format(field_val, DATETIME_FORMAT))
elif isinstance(f, meta.TimeField):
result_repr = capfirst(dateformat.time_format(field_val, TIME_FORMAT))
else: else:
result_repr = dateformat.format(field_val, 'N j, Y') result_repr = capfirst(dateformat.format(field_val, DATE_FORMAT))
else: else:
result_repr = EMPTY_CHANGELIST_VALUE result_repr = EMPTY_CHANGELIST_VALUE
row_class = ' class="nowrap"' row_class = ' class="nowrap"'
Expand Down
39 changes: 39 additions & 0 deletions docs/settings.txt
Expand Up @@ -258,6 +258,32 @@ Default: ``''`` (Empty string)


The username to use when connecting to the database. Not used with SQLite. The username to use when connecting to the database. Not used with SQLite.


DATE_FORMAT
-----------

Default: ``'N j, Y'`` (e.g. ``Feb. 4, 2003``)

The default formatting to use for date fields on Django admin change-list
pages -- and, possibly, by other parts of the system. See
`allowed date format strings`_.

See also DATETIME_FORMAT and TIME_FORMAT.

.. _allowed date format strings: http://www.djangoproject.com/documentation/templates/#now

DATETIME_FORMAT
---------------

Default: ``'N j, Y, P'`` (e.g. ``Feb. 4, 2003, 4 p.m.``)

The default formatting to use for datetime fields on Django admin change-list
pages -- and, possibly, by other parts of the system. See
`allowed date format strings`_.

See also DATE_FORMAT and TIME_FORMAT.

.. _allowed date format strings: http://www.djangoproject.com/documentation/templates/#now

DEBUG DEBUG
----- -----


Expand Down Expand Up @@ -482,6 +508,19 @@ Default: ``('django.core.template.loaders.filesystem.load_template_source',)``
A tuple of callables (as strings) that know how to import templates from A tuple of callables (as strings) that know how to import templates from
various sources. See the `template documentation`_. various sources. See the `template documentation`_.


TIME_FORMAT
-----------

Default: ``'P'`` (e.g. ``4 p.m.``)

The default formatting to use for time fields on Django admin change-list
pages -- and, possibly, by other parts of the system. See
`allowed date format strings`_.

See also DATE_FORMAT and DATETIME_FORMAT.

.. _allowed date format strings: http://www.djangoproject.com/documentation/templates/#now

TIME_ZONE TIME_ZONE
--------- ---------


Expand Down

0 comments on commit d4df074

Please sign in to comment.