Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NightclubBookingForm(BaseBookingForm):
- formfield_callback = customise_fields
- def __init__(self, *args, **kwargs):
- super(NightclubBookingForm, self).__init__(*args, **kwargs)
- self.fields['booking_start'].widget.attrs['autocomplete'] = 'off'
- self.fields['venue'].queryset = Venue.objects.filter(venue_type__name='Nightclub')
- if 'data' in kwargs:
- booths = Booth.objects.filter(area_layout__area__venue_id=kwargs['data']['venue'])
- booth_choices = []
- for booth in booths:
- booth_choices.append((booth.id, booth.name))
- self.fields['booth'].widget.choices = booth_choices
- else:
- self.fields['booth'].widget.choices = []
- self.fields['booth'].widget.attrs['disabled'] = 'disabled'
- self.fields['booth'].widget.attrs['class'] = 'select_booth'
- class Meta:
- model = NightclubBooking
- fields = ('customer', 'venue', 'booth', 'booking_start', 'pax', 'notes')
- def customise_fields(f):
- """
- Ensure all date & datetime fields in the form have the jquery datepicker
- applied to them
- """
- if isinstance(f, models.DateTimeField):
- datetime_field = forms.DateTimeField(
- widget=forms.DateTimeInput(
- format='%d/%m/%Y %H:%M',
- attrs={'class': 'datetimepicker'}
- ),
- input_formats=['%d/%m/%Y', '%d/%m/%Y %H:%M'])
- return datetime_field
- elif isinstance(f, models.DateField):
- date_field = forms.DateField(
- widget=forms.DateInput(
- format='%d/%m/%Y',
- attrs={'class': 'datepicker'}
- ),
- input_formats=['%d/%m/%Y'])
- return date_field
- else:
- return f.formfield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement