@@ -9,9 +9,7 @@ configured easily for date-range selection. For Bootstrap date-picker see
99`django-bootstrap-datepicker-plus <https://github.com/monim67/django-bootstrap-datepicker-plus >`_.
1010
1111
12- | |ci-status| |coverage.io|
13- | |pyversions| |djversions| |pypi-version|
14- | |format| |status| |license|
12+ | |ci-status| |coverage| |pyversions| |djversions|
1513
1614| |flatpickr-red-theme| |flatpickr-default-theme| |flatpickr-dark-theme|
1715
2220- `Custom Form <demo_custom_form _>`_.
2321- `Model Form <demo_model_form _>`_.
2422- `Generic View (without Model Form) <demo_generic_view _>`_.
23+ - `With django-crispy-forms <demo_crispy_form _>`_.
24+ - `With django-filter <demo_django_filter _>`_.
25+ - `With dynamic formsets <demo_dynamic_formset _>`_.
2526
2627
2728
@@ -31,7 +32,7 @@ Getting Started
3132
3233Prerequisites
3334^^^^^^^^^^^^^
34- - Python >= 3.4
35+ - Python >= 3.7
3536- Django >= 2.0
3637
3738
@@ -43,13 +44,13 @@ Install the PyPI package via pip.
4344
4445 pip install django-flatpickr
4546
46- Add ``flatpickr `` to ``INSTALLED_APPS `` in your ``settings.py `` file.
47+ Add ``django_flatpickr `` to ``INSTALLED_APPS `` in your ``settings.py `` file.
4748
4849.. code :: python
4950
5051 INSTALLED_APPS = [
5152 # Add the following
52- ' flatpickr ' ,
53+ " django_flatpickr " ,
5354 ]
5455
5556
@@ -62,7 +63,7 @@ A better example is `here <file_custom_form_html_>`_.
6263
6364.. code :: html
6465
65- <!-- File: todo .html -->
66+ <!-- File: myapp/custom-form .html -->
6667 {{ form.media }} {# Adds all flatpickr JS/CSS files from CDN #}
6768 {{ form.as_p }} {# Renders the form #}
6869
@@ -77,7 +78,7 @@ Usage in Custom Form
7778.. code :: python
7879
7980 # File: forms.py
80- from flatpickr import DatePickerInput, TimePickerInput, DateTimePickerInput
81+ from django_flatpickr.widgets import DatePickerInput, TimePickerInput, DateTimePickerInput
8182 from .models import Event
8283 from django import forms
8384
@@ -90,7 +91,7 @@ Usage in Custom Form
9091
9192 # File: views.py
9293 class CustomFormView (generic .FormView ):
93- template_name = ' myapp/custom-form.html'
94+ template_name = " myapp/custom-form.html"
9495 form_class = ToDoForm
9596
9697
@@ -104,18 +105,18 @@ Usage in Model Form
104105.. code :: python
105106
106107 # File: forms.py
107- from flatpickr import DatePickerInput, TimePickerInput, DateTimePickerInput
108+ from django_flatpickr.widgets import DatePickerInput, TimePickerInput, DateTimePickerInput
108109 from .models import Event
109110 from django import forms
110111
111112 class EventForm (forms .ModelForm ):
112113 class Meta :
113114 model = Event
114- fields = [' name' , ' start_date' , ' start_time' , ' start_datetime' ]
115+ fields = [" name" , " start_date" , " start_time" , " start_datetime" ]
115116 widgets = {
116- ' start_date' : DatePickerInput(),
117- ' start_time' : TimePickerInput(),
118- ' start_datetime' : DateTimePickerInput(),
117+ " start_date" : DatePickerInput(),
118+ " start_time" : TimePickerInput(),
119+ " start_datetime" : DateTimePickerInput(),
119120 }
120121
121122
@@ -138,18 +139,18 @@ date-time-range **without writing a single line of JavaScript**.
138139.. code :: python
139140
140141 # File: forms.py
141- from flatpickr import DatePickerInput, TimePickerInput
142+ from django_flatpickr.widgets import DatePickerInput, TimePickerInput
142143 from django import forms
143144
144145 class EventForm (forms .ModelForm ):
145146 class Meta :
146147 model = Event
147- fields = [' name' , ' start_date' , ' end_date' , ' start_time' , ' end_time' ]
148+ fields = [" name" , " start_date" , " end_date" , " start_time" , " end_time" ]
148149 widgets = {
149- ' start_date' : DatePickerInput().start_of( ' event days ' ),
150- ' end_date' : DatePickerInput().end_of( ' event days ' ),
151- ' start_time' : TimePickerInput().start_of( ' party time ' ),
152- ' end_time' : TimePickerInput().end_of( ' party time ' ),
150+ " start_date" : DatePickerInput(),
151+ " end_date" : DatePickerInput(range_from = " start_date " ),
152+ " start_time" : TimePickerInput(),
153+ " end_time" : TimePickerInput(range_from = " start_time " ),
153154 }
154155
155156
@@ -161,29 +162,50 @@ To customize the look and features of flatpickr widget copy the
161162`settings block <settings_block _>`_ to your settings.py file and customize it.
162163Settings applies globally to all flatpickr widgets used in your site.
163164
164- If you need to customize a single flatpickr widget you can do it as follows:
165+ You can set date and event hook options using JavaScript.
166+
167+ .. code :: javascript
168+
169+ window .djangoFlatpickrOptions = {
170+ onChange : function (selectedDates ) { console .log (selectedDates) }
171+ }
172+
173+
174+ Customize single input
175+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
165176
166177.. code :: python
167178
179+ from django_flatpickr.schemas import FlatpickrOptions
180+
168181 class ToDoForm (forms .Form ):
169182 todo = forms.CharField(widget = forms.TextInput())
170- date = forms.DateField(widget = DatePickerInput(
171- attrs = { # input element attributes
172- " class" : " my-custom-class" ,
173- },
174- options = { # flatpickr options
175- " dateFormat" : " m/d/Y" ,
176- }
183+ start_date = forms.DateField(widget = DatePickerInput(
184+ attrs = {" class" : " my-custom-class" }, # input element attributes
185+ options = FlatpickrOptions(altFormat = " m/d/Y" ),
177186 ))
178187
188+ Similarly set date and event hook options using JavaScript.
189+
190+ .. code :: javascript
191+
192+ window .djangoFlatpickrOptions_start_date = {
193+ onChange : function (selectedDates ) { console .log (selectedDates) }
194+ }
195+
196+
197+ Localization
198+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
199+
200+ Use locale option, see `available localization options <https://flatpickr.js.org/localization/ >`_.
179201
180202
181203License
182204-------
183205
184- - `MIT LICENSE <https://github.com/monim67/django-flatpickr/blob/master/LICENSE >`_.
185- - `CONTRIBUTING <https://github.com/monim67/django-flatpickr/blob/master/.github/CONTRIBUTING.md >`_.
186- - `CODE_OF_CONDUCT <https://github.com/monim67/django-flatpickr/blob/master/.github/CODE_OF_CONDUCT.md >`_.
206+ - `MIT LICENSE <https://github.com/monim67/django-flatpickr/blob/master/LICENSE >`_.
207+ - `CONTRIBUTING <https://github.com/monim67/django-flatpickr/blob/master/.github/CONTRIBUTING.md >`_.
208+ - `CODE_OF_CONDUCT <https://github.com/monim67/django-flatpickr/blob/master/.github/CODE_OF_CONDUCT.md >`_.
187209
188210
189211.. |flatpickr-red-theme | image :: https://cloud.githubusercontent.com/assets/11352152/14549374/3cc01102-028d-11e6-9ff4-0cf208a310c4.PNG
@@ -200,7 +222,7 @@ License
200222 :target: https://travis-ci.org/monim67/django-flatpickr
201223 :alt: Build Status
202224
203- .. |coverage.io | image :: https://coveralls.io/repos/github/monim67/django-flatpickr/badge.svg?branch=master
225+ .. |coverage | image :: https://coveralls.io/repos/github/monim67/django-flatpickr/badge.svg?branch=master
204226 :target: https://coveralls.io/github/monim67/django-flatpickr?branch=master
205227 :alt: Coverage Status
206228
@@ -212,33 +234,20 @@ License
212234 :target: https://pypi.python.org/pypi/django-flatpickr
213235 :alt: DJango Versions
214236
215- .. |pypi-version | image :: https://badge.fury.io/py/django-flatpickr.svg
216- :target: https://pypi.python.org/pypi/django-flatpickr
217- :alt: PyPI version
218-
219- .. |format | image :: https://img.shields.io/pypi/format/django-flatpickr.svg
220- :target: https://pypi.python.org/pypi/django-flatpickr
221- :alt: Format
222-
223- .. |status | image :: https://img.shields.io/pypi/status/django-flatpickr.svg
224- :target: https://pypi.python.org/pypi/django-flatpickr
225- :alt: Status
226-
227- .. |license | image :: https://img.shields.io/pypi/l/django-flatpickr.svg
228- :target: https://pypi.python.org/pypi/django-flatpickr
229- :alt: Licence
230237
231238
232239.. _demo_custom_form : https://monim67.github.io/django-flatpickr/demo/custom-form.html
233240.. _demo_model_form : https://monim67.github.io/django-flatpickr/demo/generic-view-with-model-form-1.html
234241.. _demo_generic_view : https://monim67.github.io/django-flatpickr/demo/generic-view.html
235-
236- .. _generic_view_block : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/myapp/views.py#L11
237- .. _settings_block : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/mysite/settings.py#L134-L176
238-
239- .. _file_custom_form_html : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/myapp/templates/myapp/custom-form.html
240- .. _file_event_form_html : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/myapp/templates/myapp/event_form.html
241- .. _file_forms_py : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/myapp/forms.py
242- .. _file_views_py : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/myapp/views.py
243- .. _file_models_py : https://github.com/monim67/django-flatpickr/blob/v1.0.0/dev/myapp/models.py
244-
242+ .. _demo_crispy_form : https://monim67.github.io/django-flatpickr/demo/crispy-form.html
243+ .. _demo_django_filter : https://monim67.github.io/django-flatpickr/demo/django-filter.html
244+ .. _demo_dynamic_formset : https://monim67.github.io/django-flatpickr/demo/dynamic-formset.html
245+
246+ .. _generic_view_block : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/myapp/views.py#L31
247+ .. _settings_block : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/mysite/settings.py#L143-L200
248+
249+ .. _file_custom_form_html : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/myapp/templates/myapp/custom-form.html
250+ .. _file_event_form_html : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/myapp/templates/myapp/event_form.html
251+ .. _file_forms_py : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/myapp/forms.py
252+ .. _file_views_py : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/myapp/views.py
253+ .. _file_models_py : https://github.com/monim67/django-flatpickr/blob/2.0.0/dev/myapp/models.py
0 commit comments