class Meta: model = User fields = [ 'username', 'DPI', 'Photo', 'Name1', 'Name2', 'Name3', 'LastName1', 'LastName2', 'BirthDate', 'Email', 'Phone', 'FKLicenceType', ] labels = { 'username': '******', 'DPI': 'DPI', 'Photo': 'Photo', 'Name1': 'Name1', 'Name2': 'Name2', 'Name3': 'Name3', 'LastName1': 'LastName', 'LastName2': 'LastName2', 'BirthDate': 'BirthDate', 'Email': 'Email', 'Phone': 'Phone', 'FKLicenceType': 'FKLicenceType', } years = [x for x in range(1980, 2019)] widgets = { 'username': widgets.TextInput(attrs={'class': ''}), 'DPI': widgets.TextInput(), 'Photo': widgets.FileInput(), 'Name1': widgets.TextInput(attrs={'class': ''}), 'Name2': widgets.TextInput(attrs={'class': ''}), 'Name3': widgets.TextInput(attrs={'class': ''}), 'LastName1': widgets.TextInput(attrs={'class': ''}), 'LastName2': widgets.TextInput(attrs={'class': ''}), 'Email': widgets.TextInput(attrs={'class': ''}), 'Phone': widgets.TextInput(attrs={'class': ''}), 'BirthDate': widgets.SelectDateWidget(attrs={'class': ''}, years=years), 'FKLicenceType ': widgets.Select(attrs={'class': ''}), }
class Meta: model = CreditCard exclude = ['id'] widgets = { 'credit_card': widgets.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Credit Card Number.' }), 'exp_date': widgets.SelectDateWidget(attrs={'class': 'form-control'}), 'csv': widgets.TextInput( attrs={ 'class': 'form-control', 'placeholder': '3 digit number on back of card.' }), }
class Meta: model = Profile fields = ( 'patronymic', 'birth', ) widgets = { 'patronymic': forms.TextInput(attrs={'class': 'form-control'}), 'birth': widgets.SelectDateWidget( attrs={'class': 'col-md-3 ml-3 form-control'}, years=range(datetime.datetime.now().year, 1950, -1)) } def __init__(self, *args, **kwargs): self.fields['patronymic'].required = False self.fields['birth'].required = False
class Meta: model = ReserveAirspace fields = ( "start_day", "start_time", "end", "geom", "status", "reason", "comments", ) widgets = { "geom": LeafletWidget(), "start_day": widgets.SelectDateWidget(), "start_time": TimePickerInput(), "end": TimePickerInput(), # 'rpas': forms.widgets.Select(attrs={'readonly': True, # 'disabled': True}) }
class Meta: model = Appointment fields = [ 'description', 'location', 'date', 'time', 'endTime', 'patient_ID', ] exclude = [ 'doctor_ID', ] widgets = { 'description': widgets.TextInput(attrs={'class': 'form-control'}), 'location': widgets.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Location' }), 'date': widgets.SelectDateWidget( years=[timezone.now().year, timezone.now().year + 1]), 'time': widgets.TimeInput(attrs={ 'type': 'time', 'class': 'form-control' }, format='%H:%M'), 'endTime': widgets.TimeInput(attrs={ 'type': 'time', 'class': 'form-control' }, format='%H:%M'), 'patient_ID': widgets.Select(attrs={'class': 'form-control'}), }
class Meta: model = models.Alumni readonly_fields = ('cycle', 'folio', 'register_date', 'modified_date', ) fields = ( 'agreement', 'child_name', 'child_familynames', 'child_dob', 'child_curp_id', 'child_gender', 'child_schedule', 'child_group', 'child_blood_type', 'child_photo', 'child_observations', 'emergency_telephone_number', 'emergency_contact',) widgets = {'child_dob': widgets.SelectDateWidget( years=range( 2006, datetime.date.today().year + 1)), 'child_observations': Textarea(attrs={'cols': 60, 'rows': 3})}
class TaskForm(forms.Form): description = forms.CharField(max_length=50, label='Описание', required=True) full_description = forms.CharField(max_length=3000, label='Полное описание', required=False, widget=forms.Textarea(attrs={ 'rows': 4, 'cols': 15 })) status = forms.ChoiceField(label='Статус', required=True, choices=STATUS_CHOICES) execution_date = forms.DateField(label='Дата выполнения', required=False, widget=widgets.SelectDateWidget( years=YEARS_CHOICES, empty_label=("Выберите год", "Выберите месяц", "Выберите день")))
class BookForm(forms.Form): title = forms.CharField( min_length=1, label='图书名称', error_messages={'required': '图书名称不能为空'}, widget=widgets.TextInput(attrs={'class': 'form-control'})) price = forms.DecimalField( decimal_places=2, label='图书价格', error_messages={ 'required': '图书价格不能为空', 'invalid': '请输入数字' }, widget=widgets.TextInput(attrs={'class': 'form-control'})) author = forms.MultipleChoiceField( choices=AUTHORS, label='作者', error_messages={'required': '作者不能为空'}, widget=widgets.SelectMultiple(attrs={'class': 'form-control'})) pub_data = forms.DateField(label='出版日期', error_messages={'required': '日期不能为空'}, widget=widgets.SelectDateWidget( months=MONTHS, years=YEAR, attrs={'class': 'form-control'})) publish = forms.ChoiceField( label='出版社名称', choices=PUBLISHS, error_messages={'required': '图书名称不能为空'}, widget=widgets.Select(attrs={'class': 'form-control'})) def clean_price(self): val = self.cleaned_data.get('price') if val < 0: raise ValidationError('价格不能为负数') else: return val
class Meta: model = CustomUser fields = [ 'email', 'first_name', 'last_name', 'phone_number', 'street_address', 'birth_date', 'gender', 'bio' ] widgets = { 'birth_date': widgets.SelectDateWidget(years=range(1900, date.today().year + 1)), # TODO: possible to switch to a jquery datepicker once the localization # issue is fixed (see the user profile form, and base.html # # 'birth_date': forms.DateInput(attrs={'class':'datepicker'}), 'email': widgets.EmailInput(attrs={'type': 'email'}), 'phone_number': widgets.TextInput(attrs={ 'type': 'tel', 'placeholder': '+336012345678' }), } localized_fields = ['birth_date']
class Meta: model = Post exclude = ('auteur', 'date_creation') widgets = { 'date_evenement': widgets.SelectDateWidget(), }
class DemoForm(MaterialForm): """Demo Form with Material widget fields.""" username = forms.CharField( ### Default label uses field name.replace('_', ' ').title() #label='Username', min_length=3, max_length=32, help_text='3-32 characters required', ### Widgets can be declared as material_widgets.widgets or ### django.forms.widgets. ### Widgets will be converted to material_widgets when declared through ### MaterialForm. widget=widgets.TextInput(attrs={ 'autofocus': "autofocus", }, ), ) email = forms.EmailField(required=False, ) password = forms.CharField( help_text='Please enter at least 8 characters', required=False, min_length=8, ### Declare material_widgets.widget to use custom attributes widget=MaterialPasswordInput(persistent_help_text=True, ), ) url = forms.URLField( label='URL', required=False, initial='http://github.com/ooknosi', ) textarea = forms.CharField( help_text='Write as much as you want', required=False, widget=widgets.Textarea(), ) number = forms.IntegerField( label='Odd Number', help_text='No even numbers!', required=False, min_value=1, max_value=9, widget=widgets.NumberInput(attrs={ 'step': '2', }, ), ) slider = forms.DecimalField( label='Slider (2 decimal places)', ### help_text in sliders are persistent by default help_text='in steps of 0.25', required=False, min_value=0.0, max_value=10.0, decimal_places=2, widget=MaterialSliderInput(attrs={ 'step': '0.25', }, ), ) slider_discrete = forms.IntegerField( label='Slider (Even Number with Markers)', required=False, min_value=0, max_value=10, initial=6, widget=MaterialSliderInput( is_discrete=True, display_markers=True, attrs={ 'step': '2', }, ), ) date_field = forms.DateField( help_text='YYYY-MM-DD', required=False, ) time_field = forms.TimeField( help_text='HH:MM:SS', required=False, ) datetime_field = forms.DateTimeField( help_text='YYYY-MM-DD HH:MM:SS', required=False, ) split_datetime = forms.SplitDateTimeField( required=False, ### Declare material_widgets.widget to override default attributes #widget=MaterialSplitDateTimeWidget( # date_label='Birthdate', # date_help_text='YYYY-MM-DD', # date_persistent_help_text=True, # time_label='Birthtime', # time_help_text='HH:MM:SS', # time_persistent_help_text=True, # ), ) date_select = forms.DateField( ### Help_text on non-textfields appear as label tooltips help_text='This is a select date', required=False, widget=widgets.SelectDateWidget( years=[ year for year in range(datetime.now().year, datetime.now().year - 100, -1) ], empty_label=("Year", "Month", "Day"), )) select = forms.ChoiceField( ### Blank the label on a select to use the first item as the label label='', required=False, choices=( ('', 'Select'), ('choice_1', 'Choice 1'), ('choice_2', 'Choice 2'), ('choice_3', 'Choice 3'), ), ) select_with_groups = forms.ChoiceField( label='', required=False, choices=( ('', 'Select with Groups'), ('Group 1', ( ('group_1_choice_1', 'Group 1 Choice 1 '), ('group_1_choice_2', 'Group 1 Choice 2'), ('group_1_choice_3', 'Group 1 Choice 3'), )), ('Group 2', ( ('group_2_choice_4', 'Group 2 Choice 4'), ('group_2_choice_5', 'Group 2 Choice 5'), ('group_2_choice_6', 'Group 2 Choice 6'), )), ), ) null_boolean_select = forms.NullBooleanField( help_text='This is a null boolean select', required=False, ) select_multiple = forms.MultipleChoiceField( label='', #help_text='A label is needed to show the help text tooltip', required=False, choices=( ('Select Multiple 1', ( ('multiple_choice_1', 'Multiple Choice 1'), ('multiple_choice_2', 'Multiple Choice 2'), ('multiple_choice_3', 'Multiple Choice 3'), )), ('Select Multiple 2', ( ('multiple_choice_4', 'Multiple Choice 4'), ('multiple_choice_5', 'Multiple Choice 5'), ('multiple_choice_6', 'Multiple Choice 6'), )), ), ) boolean_switch = forms.BooleanField( label='Boolean Switch', help_text='This is a switch', required=False, widget=MaterialSwitchInput(), ) radio_select = forms.ChoiceField( label='Radio Select', ### help_text for multiple choices can be list or tuple help_text=[ 'This is radio 1', 'This is radio 2', 'This is radio 3', ], required=False, widget=widgets.RadioSelect(), choices=( ('radio_select_1', 'Radio 1'), ('radio_select_2', 'Radio 2'), ('radio_select_3', 'Radio 3'), ), ) checkbox = forms.BooleanField( label='Checkbox', help_text='This is a checkbox', required=False, ) checkbox_select_multiple = forms.MultipleChoiceField( label='Multiple Checkboxes', help_text=( 'This is checkbox 1', 'This is checkbox 2', 'This is checkbox 3', ), required=False, widget=MaterialCheckboxSelectMultiple(is_vertical=True, ), choices=( ('checkbox_1', 'Checkbox 1'), ('checkbox_2', 'Checkbox 2'), ('checkbox_3', 'Checkbox 3'), ), ) file_input = forms.FileField( ### Blank the label to only display the icon label='', help_text='Choose 1 file', required=False, ### Declare material_widgets.widget to use custom attributes widget=MaterialFileInput( ### compact, dense, raised, stroked, unelevated button=('compact', 'dense', 'raised'), ### From material-icons; https://material.io/icons/ icon='attachment', ), ) clearable_file_input = forms.FileField( label='Select Files', help_text='Choose 1 or more files', required=False, widget=MaterialClearableFileInput( icon='file_upload', attrs={ 'multiple': True, }, ), ) hidden_input = forms.CharField( initial='hidden_value', widget=widgets.HiddenInput(), ) multiple_hidden_input = forms.MultipleChoiceField( initial=[ 'hidden_1', 'hidden_2', 'hidden_3', ], widget=widgets.MultipleHiddenInput(), choices=( ('hidden_1', 'Hidden 1'), ('hidden_2', 'Hidden 2'), ('hidden_3', 'Hidden 3'), ), ) split_hidden_datetime = forms.SplitDateTimeField( initial=['1965-08-09', '12:00:00'], widget=widgets.SplitHiddenDateTimeWidget(), )
class Meta: model = models.Task fields = ['title', 'estimate', 'state', 'roadmap'] widgets = { 'estimate': widgets.SelectDateWidget(), }
def __init__(self, *args, **kwargs): super(ProfileUpdateForm, self).__init__(*args, **kwargs) self.profile = self.instance self.fields['birth_date'].widget = widgets.SelectDateWidget( years=YEARS)
class Meta: model = Trans fields = '__all__' widgets = { 'trans_date': widgets.SelectDateWidget(), }
class ForecastForm(forms.Form): date = forms.DateField( initial=datetime.date.today(), widget=widgets.SelectDateWidget(years=range(2000, 2050)))