asaglimbeni / django-datetime-widget

Bootstrap django-datetime-widget is a simple and clean widget for DateField, Timefiled and DateTimeField in Django framework. It is based on Bootstrap datetime picker, supports both Bootstrap 3 and Bootstrap 2
Other
218 stars 125 forks source link

startDate and endDate Options #107

Open lowjumpingfrog opened 6 years ago

lowjumpingfrog commented 6 years ago

The documentation is not very clear about what format these should be in so, for those looking for the answer.... for start and end dates for current day the option might look like this:

dateTimeOptions = {
            'format': 'dd/mm/yyyy HH:ii',
            'autoclose': True,
            'showMeridian' : True,
            'endDate':  str(datetime.datetime.today().date())
        }

or

dateTimeOptions = {
            'format': 'dd/mm/yyyy HH:ii',
            'autoclose': True,
            'showMeridian' : True,
            'startDate':  str(datetime.datetime.today().date())
        }

You need to import datetime into your forms.py for the examples above to work. The javascript in the datetimewidget is expecting a string. The Javascript Date object is pretty happy with a variety of strings. See docs for ones you might ask Django to create or just add your own. Ciao