Last active
July 4, 2021 00:19
-
-
Save rg3915/26c5591e0bd0ce82a2234da7f443591f to your computer and use it in GitHub Desktop.
Insert required with widget in input forms.py widget all fields form widget required_css_class required css required form date format datefield datetime-local
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from .models import Expense, Person | |
class PersonForm(ModelForm): | |
cpf = forms.CharField( | |
label=_('CPF'), | |
widget=forms.TextInput(attrs={'required': 'True'}) | |
) | |
class Meta: | |
model = Person | |
fields = ('cpf', ) | |
widgets = { | |
'rg': forms.TextInput(attrs={'required': 'True'}), | |
} | |
class ExpenseForm(forms.ModelForm): | |
required_css_class = 'required' | |
payment_date = forms.DateField( | |
label='Data de pagamento', | |
widget=forms.DateInput( | |
format='%Y-%m-%d', | |
attrs={ | |
'type': 'date', | |
}), | |
input_formats=('%Y-%m-%d',), | |
required=False, | |
) | |
etd = forms.DateTimeField( | |
label='ETD', | |
widget=forms.DateTimeInput( | |
format='%Y-%m-%d %H:%i:%s', | |
attrs={ | |
'type': 'datetime-local', | |
}), | |
input_formats=('%Y-%m-%d %H:%i:%s',), | |
) | |
class Meta: | |
model = Expense | |
fields = ('description', 'payment_date', 'customer', 'value') | |
def __init__(self, *args, **kwargs): | |
super(ExpenseForm, self).__init__(*args, **kwargs) | |
for field_name, field in self.fields.items(): | |
field.widget.attrs['class'] = 'form-control' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment