Last active
December 14, 2015 11:49
-
-
Save jleinonen/5082363 to your computer and use it in GitHub Desktop.
Django widget for bootstrap-datetimepicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.utils.safestring import mark_safe | |
class DateTimeWidget(forms.DateTimeInput): | |
class Media: | |
css = { | |
"all": ("bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css",) | |
} | |
js = ("bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js") | |
def __init__(self, attrs=None, format=None): | |
format = "%Y-%m-%d %H:%M:%S" #this is fixed for now | |
if attrs is None: | |
attrs = {} | |
attrs.update({"data-format": "yyyy-MM-dd hh:mm:ss"}) | |
super(DateTimeWidget, self).__init__(attrs, format=format) | |
def render(self, name, value, attrs=None): | |
return mark_safe( | |
u'<div class="input-append">' + \ | |
super(DateTimeWidget, self).render(name, value, attrs) + \ | |
u'<span class="add-on"><i class="icon-calendar" ' + \ | |
u'data-time-icon="icon-time" data-date-icon="icon-calendar">' + \ | |
u'</i></span></div>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment