Question

python 2.7.5+. django_tables2 0.14.0

In settings.py:

USE_L10N = True
DATETIME_FORMAT = 'M j, Y H:i:s.u'

Didn't work. I tried {% load L10N %} at the top of my template. Didn't work.

I created a formats directory at the top of my project containing an en directory containing formats.py and added the following to my settings.py (yes, there are init.py files in the formats directory and in the en directory):

FORMAT_MODULE_PATH = '<project>.formats'

Didn't work.

I tried putting in {{created_at|date: 'M j, Y'}}{{created_at|time: 'H:i:s.u'}} before the {% render_table table %} tag from django_tables2. Got an error.

Tried the recommended django_tables2 method of, in my tables.py definition, adding to the Meta class:

localize('created_at')

Didn't work.

Tried putting 'localize=True' in the column definition for created_at in tables.py.

Didn't work.

The only thing that worked was modifying python2.7/site-packages/django/conf/locale/en/formats.py (in my virtual environment) but I won't be allowed to do that on my project because it's not considered portable.

I see stackoverflow entries that say this works but they are many years old and many django versions back. I see others here that say this doesn't work and they haven't/aren't going to fix it.

This functionality logs requests; during testing the other devs could really use seeing seconds and probably microseconds to help them debug but I can't seem to give it to them.

Any suggestions that I haven't already tried?

Thanks.

No correct solution

OTHER TIPS

OK, blush - I got it. I made the following change in the model for the DateTimeField created_at:

@property
    def nice_date(self):
        # mm/dd/yyyy HH:mm:ss.uuuuuu
        t = self.created_at.strftime("%m/%d/%Y %H:%M:%S.%f")
        return t

Then, I displayed nice_date instead of created_at.

I hope this helps someone else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top