Updating TimeField in forms/formsets returns value without microseconds

51 views
Skip to first unread message

RafaƂ Szymczuk

unread,
Mar 25, 2018, 9:03:18 AM3/25/18
to Django users
I have problem with updating TimeField in my models - when I want to edit objects using forms/formsets the input field on my site is always cutting microseconds.
I made ex. class with TimeField:
class Participant(models.Model):
    surname = models.CharField(max_length = 256)
    name = models.CharField(max_length = 256)
    birth = models.DateField(blank = True, null = True)
    entry_time = models.TimeField(blank = True, null = True)
                      ...
Then I made a form:
class ParticipantForm(forms.ModelForm):
       ....
       entry_time = forms.TimeField(initial="HH:MM:SS.00", 
       required = False, 
       widget=forms.TimeInput(format=('%H:%M:%S.%f')))
       ....
When I am adding new Participant via my form everything is OK. Value of entry_time is saving in my database (SQLite) with properly format(hours:minutes:seconds.microseconds). But there is a problem when I want to update my participants using this form or formsets. Data loaded to form is always without microseconds (hours:minutes:seconds).

The output on my site looks like this:

https://lh3.googleusercontent.com/-FKuX_loplIU/WreCImNW33I/AAAAAAAALoM/6MA-z2LnD6MIhknumZNZTYOK5iif1KdbwCLcBGAs/s1600/timeformat.PNG

first generated by: {{ formset.time_score }} 
second: <input type="text" value="{{ participant.time_score|time:"H:i:s:u" }}">
It doesn't metter if I use form or formset - results are the same.

Hope for your help guys, i can't figure it out.

Tim Graham

unread,
Mar 26, 2018, 10:30:46 AM3/26/18
to Django users
Reply all
Reply to author
Forward
0 new messages