1

I'm currently working on a website in Django, where data from a MySQL database is shown with Django-Tables2. The issue is that all TIME fields in the database gets converted into am/pm instead of 24 hours as the standard should be from what I've gathered. I've seen multiple of people with the opposite issue but none of those solutions has worked. After googling and trying for almost a week, I'm not asking the community.

Is there a way to force the time standard for the TimeFormat fields in Django to correspond to the same format as the MySQL TIME (unlimited/24 hours)?

It would be very helpful as I'm currently displaying time intervals, and 00:25 which should be 25 minutes is shown as 12:25 pm.

class LoggTable(TableReport):
    glider = tables.Column(accessor = 'glider.glider_id')
    towing = tables.Column(accessor = 'towing.towing_id')
    glider_pilot = tables.Column(accessor = 'glider_pilot.pilot_id')
    towing_pilot = tables.Column(accessor = 'towing_pilot.pilot_id')

    class Meta :
        model = FlightData
        exclude = ('max_height')
        attrs = {'class': 'paleblue'}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Are you using a time field to represent a time interval? That's not what they're for. Use an integer instead. – Nils Werner May 10 '17 at 08:24
  • I'm storing a time interval in MySQL using the TIME datatype, here's why, which is then shown by django-tables2 but in the wrong format http://stackoverflow.com/questions/4498513/mysql-storing-duration-time-datatype How would one go about using an integer to separate hours, minutes and seconds? – Joakim Ingnäs May 10 '17 at 08:25
  • Why are you using `TIME`? The answer you provided specifically says "use an `INT`", saving the number of seconds in your interval. – Nils Werner May 10 '17 at 08:27
  • I'm using time because the maximum time interval that's needed is roughly 12 hours and the other issue with Django displaying time as am/pm instead of 24 hours is that the start/end-time fields is shown as am/pm and the application should show it as 24 hours time – Joakim Ingnäs May 10 '17 at 08:30
  • That's no reason. It is not meant for intervals, so don't use it! – Nils Werner May 10 '17 at 08:31
  • That still doesn't answer the original issue which is that Django displays TimeField data as am/pm as a standard instead of its standard 24hr military time which it should do according to different threads. There's nothing in the settings file that should affect displaying the time – Joakim Ingnäs May 10 '17 at 08:33
  • can you show the code you are using to define your table? – Nils Werner May 10 '17 at 10:21
  • Added the code to the question, that's all I have in my tables.py for this certain table, the rest is defined in the models. – Joakim Ingnäs May 11 '17 at 08:00
  • We're also using timefield type in models when defining our other time fields – Joakim Ingnäs May 11 '17 at 09:30

1 Answers1

0

We solved the issue, by including

TIME_FORMAT = 'H:i'

In our settings.py file, we tried similar different solutions before but didn't find this until now. We also set

USE_L10N = False