daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from bootstrap_datepicker.widgets import DatePicker
  2. class DateInput(DatePicker):
  3.     def __init__(self):
  4.         DatePicker.__init__(self,format="%Y-%m-%d")
  5.     def build_attrs(self, attrs, extra_attrs=None, **kwargs):
  6.         attrs = dict(self.attrs, **kwargs)
  7.         if extra_attrs:
  8.             attrs.update(extra_attrs)
  9.         return attrs
  10.  
  11. class LodgingOfferForm(forms.ModelForm):
  12.  
  13.     class Meta:
  14.         widgets = {
  15.             'check_in': DateInput(),
  16.             'check_out': DateInput(),
  17.         }
  18.         model = LodgingOffer
  19.         fields = ('other fields', 'check_in', 'check_out', )
  20.    
  21. {% load bootstrap3 %}
  22. {% block body_content %}
  23.  
  24. {% block extrahead %}   {# Extra Resources Start #}
  25.    {{ form.media }}        {# Form required JS and CSS #}
  26. {% endblock %}
  27.  
  28. {% bootstrap_field form.check_in %}
  29. {% bootstrap_field form.check_out %}
  30. {% endblock %}
  31.    
  32. class Meta:
  33.     widgets = {
  34.         'check_in': DateInput(),
  35.         'check_out': DateInput(),
  36.     }
  37.     model = LodgingOffer
  38.     fields = ('check_in', 'check_out', )
  39.  
  40. def __init__(self, *args, **kwargs):
  41.     super(LodgingOfferForm, self).__init__(*args, **kwargs)
  42.     self.fields['check_in'].widget.attrs['class'] = 'input-group input-daterange'
  43.     self.fields['check_out'].widget.attrs['class'] = 'input-group input-daterange'
  44.    
  45. <script>
  46.         $('.input-daterange input').each(function() {
  47.             $(this).datepicker('clearDates');
  48.          });
  49.     </script>
RAW Paste Data
Top