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
219 stars 125 forks source link

django-datetime-widget

.. image:: https://pypip.in/v/django-datetime-widget/badge.png :target: https://crate.io/packages/django-datetime-widget .. image:: https://pypip.in/d/django-datetime-widget/badge.png :target: https://crate.io/packages/django-datetime-widget

django-datetime-widget is a simple and clean picker widget for DateField, Timefiled and DateTimeField in Django framework. It is based on Bootstrap datetime picker <https://github.com/smalot/bootstrap-datetimepicker>_, supports both Bootstrap 3 and Bootstrap 2 .

django-datetime-widget is perfect when you use a DateField, TimeField or DateTimeField in your model/form where is necessary to display the corresponding picker with a specific date/time format. Now it supports django localization.

Available widgets

See Demo page <http://bit.ly/django-datetime-widget-demo-page>_

Requirements

Screenshots

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_decade.png

This view allows the user to select the year in a range of 10 years.

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_year.png

This view allows the user to select the month in the selected year.

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_month.png

This view allows the user to select the day in the selected month.

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_day.png

This view allows the user to select the hour in the selected day.

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_hour.png

This view allows the user to select the preset of minutes in the selected hour. The range of 5 minutes (by default) has been selected to restrict button quantity to an acceptable value, but it can be overwritten by the minuteStep property.

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_day_meridian.png

Meridian is supported in both the day and hour views. To use it, just enable the showMeridian property.

.. image:: https://raw.github.com/smalot/bootstrap-datetimepicker/master/screenshot/standard_hour_meridian.png

Installation

. Install django-datetime-widget using pip. For example::

pip install django-datetime-widget

. Add datetimewidget to your INSTALLED_APPS.

If you want to use localization:

. Set USE_L10N = True, USE_TZ = True and USE_I18N = True in settings.py

. Add 'django.middleware.locale.LocaleMiddleware' to MIDDLEWARE_CLASSES in settings.py

. When you create the widget add usel10n = True like attribute : DateTimeWidget(usel10n=True)

Basic Configuration

. Create your model-form and set DateTimeWidget widget to your DateTimeField ::

from datetimewidget.widgets import DateTimeWidget

class yourForm(forms.ModelForm):
    class Meta:
        model = yourModel
        widgets = {
            #Use localization and bootstrap 3
            'datetime': DateTimeWidget(attrs={'id':"yourdatetimeid"}, usel10n = True, bootstrap_version=3)
        }

. Download twitter bootstrap <http://getbootstrap.com/>_ to your static file folder.

. Add in your form template links to jquery, bootstrap and form.media::

<head>
....
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <link href="https://github.com/asaglimbeni/django-datetime-widget/blob/master/{{ STATIC_URL }}css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <script src="https://github.com/asaglimbeni/django-datetime-widget/raw/master/{{ STATIC_URL }}js/bootstrap.js"></script>
    {{ form.media }}

....
</head>
<body>
    <form  action="" method="POST">
    {% csrf_token %}
    {{ form.as_table }}
    <input id="submit" type="submit" value="Submit">
    </form>
</body>

. Optional: you can add an option dictionary to DatetimeWidget to customize your input. For example, to have date and time with meridian::

    dateTimeOptions = {
    'format': 'dd/mm/yyyy HH:ii P',
    'autoclose': True,
    'showMeridian' : True
    }
    widgets = {
        #NOT Use localization and set a default format
        'datetime': DateTimeWidget(options = dateTimeOptions)
        }

!!! If you add 'format' into options and in the same time set usel10n as True the first one is ignored. !!!

Options

The options attribute can accept the following:

String. Default: 'dd/mm/yyyy hh:ii'

The date format, combination of P, hh, HH , ii, ss, dd, yy, yyyy.

Integer. Default: 0

Day of the week start. '0' (Sunday) to '6' (Saturday)

Date. Default: Beginning of time

The earliest date that may be selected; all earlier dates will be disabled.

Date. Default: End of time

The latest date that may be selected; all later dates will be disabled.

String. Default: ''

Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: '0,6'.

String. Default: 'true'

Whether or not to close the datetimepicker immediately when a date is selected.

Integer. Default: 2

The view that the datetimepicker should show when it is opened. Accepts values of :

Integer. Default: 0

The lowest view that the datetimepicker should show.

Integer. Default: 4

The highest view that the datetimepicker should show.

Boolean. Default: False

If true , displays a "Today" button at the bottom of the datetimepicker to select the current date. If true, the "Today" button will only move the current date into view.

Boolean. Default: False

If true, highlights the current date.

Integer. Default: 5

The increment used to build the hour view. A button is created for each minuteStep minutes.

String. Default: 'bottom-right' (other supported value : 'bottom-left')

This option allows you to place the picker just under the input field for the component implementation instead of the default position which is at the bottom right of the button.

Boolean. Default: False

This option will enable meridian views for day and hour views.

Boolean. Default: False

If true, displays a "Clear" button at the rigth side of the input value.

CHANGELOG

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. There is a Contributor Friendly_ tag for issues that should be ideal for people who are not very familiar with the codebase yet.

    • If you feel uncomfortable or uncertain about an issue or your changes, feel free to email @asaglimbeni and he will happily help you via email, Skype, remote pairing or whatever you are comfortable with.
  2. Fork develop branch from the repository_ on GitHub to start making your changes to the develop branch (or branch off of it).

  3. Please show that the bug was fixed or that the feature works as expected.

  4. Send a pull request and bug the maintainer until it gets merged and published. :)

  5. Your changes will be released on the next version of django_datetime_widget!

.. _the repository: https://github.com/asaglimbeni/django-datetime-widget .. _Contributor Friendly: https://github.com/asaglimbeni/django-datetime-widget/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open

TODO

. widget for DateTime range.