Opened 10 years ago

Closed 10 years ago

#10486 closed (duplicate)

DateTimeFormat in admin doesn't use DATETIME_FORMAT from settings

Reported by: Evgeniy Ivanov Owned by: nobody
Component: Translations Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have set DATETIME_FORMAT in the settings. I have 2 models with OneToMany relation (one has datetime and another uses fk to get datetime). In admin I get correct datetime for model, which uses function returning fk.some_datetime. Format in model containing datetime is wrong.
After checking I noticed it comes from utils.translation.get_date_formats:

    datetime_format = ugettext('DATETIME_FORMAT')
    if datetime_format == 'DATETIME_FORMAT':
        datetime_format = settings.DATETIME_FORMAT   #is never set for me

I have default localization: "LANGUAGE_CODE = 'en-us'" in settings.

Change History (4)

comment:1 Changed 10 years ago by Evgeniy Ivanov

I've noticed, I still have a problem with seconds. I've commented 'if datetime_format == 'DATETIME_FORMAT':', so DATETIME_FORMAT is taken from, but seconds look like '18:01:23.653000'...

comment:2 Changed 10 years ago by Ramiro Morales

Regarding your original report, it would be very useful if you post: a) A minimal example of the model(s) you describe and b) if you can, the value of the if datetime_format variable at the if datetime_format == 'DATETIME_FORMAT': line because if you are using en-us at that point its valus should be 'DATETIME_FORMAT'.

comment:3 Changed 10 years ago by Evgeniy Ivanov

Component: django.contrib.adminTranslations

Here it is. Somebody has translated all things...

>>> from django.utils import dateformat
>>> from django.utils.translation import get_date_formats
>>> (date_format, datetime_format, time_format) = get_date_formats()
>>> datetime_format
u'N j, Y, P'
>>> datetime_format == 'DATETIME_FORMAT'
>>> from django.conf import settings
>>> settings.DATETIME_FORMAT
'Y-m-d H:i:s'

Coolest model ever, but listing above had made all things clear:

class MTest(models.Model):
    datetime = models.DateTimeField() #adminModel should show it

About models with fk and seconds I was wrong, so don't mind about FKs and seconds.

comment:4 Changed 10 years ago by Jacob

Resolution: duplicate
Status: newclosed

Duplicate of #2203

Note: See TracTickets for help on using tickets.
Back to Top