I'm using a mysql 5.7 db and django 1.8 so as far as I understand milliseconds are supported by both of them. I can enter times in the form of HH:MM:SS.fff via mysql in to my db. (e.g. 00:05:45:100)
When I than open the admin page of django, it displays the time correctly (e.g. 00:05:45:100000) but if i enter the time via the admin form and press "save" the time becomes e.g. 00:05:45:000000 so the milliseconds don't get saved as it seems to me
Why is that and is there a way to change it? Thank you
admin.py
from django.contrib import admin from items.models import Maximum from django import forms class MaximumAdminForm(forms.ModelForm): def __init__(self, *arg, **kwargs): super(MaximumAdminForm, self).__init__(*arg, **kwargs) self.fields['time_point'] = forms.TimeField(widget=forms.TimeInput(format="%H:%M:%S.%f")) class Meta: model = Maximum fields = ['item', 'time_point',] class MaximumAdmin(admin.ModelAdmin): form = MaximumAdminForm def milliseconds(self, obj): return obj.time_point.strftime("%H:%M:%S.%f")[0:12] milliseconds.short_description = 'time point' list_display = ('id', 'milliseconds',) admin.site.register(Maximum, MaximumAdmin)