I would like to globally (through my entire site, admin and front-end) adjust the way dates and time are displayed to my likings, but I cannot figure out what is going on wi
Searching through the source shows that DATETIME_FORMAT, etc., are only used when django.utils.formats.localize()
is called, and that only seems to be called when django.template.VariableNode
s are rendered.
I'm not sure when exactly VariableNode
s are used in template rendering, but I would guess that if you have settings.USE_L10N
turned on and you have a VariableNode
, it will be localized.
localize
looks like this:
def localize(value):
"""
Checks if value is a localizable type (date, number...) and returns it
formatted as a string using current locale format
"""
if settings.USE_L10N:
if isinstance(value, (decimal.Decimal, float, int)):
return number_format(value)
elif isinstance(value, datetime.datetime):
return date_format(value, 'DATETIME_FORMAT')
elif isinstance(value, datetime.date):
return date_format(value)
elif isinstance(value, datetime.time):
return time_format(value, 'TIME_FORMAT')
return value
To answer your question, I'd probably write a quick context processor that called localize()
on everything in the context.