django-bootstrap3-datetimepicker icon indicating copy to clipboard operation
django-bootstrap3-datetimepicker copied to clipboard

TimeField is not working

Open javinievas opened this issue 9 years ago • 2 comments

If you're using a models.TimeField() and configuring the widget to something like DateTimePicker(options={"format":"HH:mm", "pickDate":False}). Should work.

It does for new objects form, but it does not work for editing an object. It tries to convert the object value to a datetime value, and obviously, that's not possible.

I think this should include some kind of check about if the value is_instance of datetime or time, to make it work in both cases.

javinievas avatar Nov 09 '14 09:11 javinievas

I've made a workaround creating a

    from django.forms.widgets import DateTimeInput, TimeInput
    [..]
    class TimePicker(TimeInput) 

Making it inherit from TimeInput instead of DateTimeInput, make everything work. I've also modified the init method to add

     self.options["format"] = "HH:mm"
     self.options["pickDate"] = False

as default options for this kind of widget.

javinievas avatar Nov 09 '14 10:11 javinievas

See https://github.com/nkunihiko/django-bootstrap3-datetimepicker/pull/30 - it closed you issue.

TyVik avatar Nov 25 '14 16:11 TyVik