Skip to content

Instantly share code, notes, and snippets.

@jleinonen
Last active December 14, 2015 11:49
Show Gist options
  • Save jleinonen/5082363 to your computer and use it in GitHub Desktop.
Save jleinonen/5082363 to your computer and use it in GitHub Desktop.
Django widget for bootstrap-datetimepicker
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