class Meta: model = Content fields = [ 'avatar', 'title', 'phone', 'address', 'email', 'link', 'summary' ] labels = { 'avatar': 'Ảnh đại diện', 'title': "Tên dịch vụ", 'phone': "Đường dây nóng", 'address': "Địa chỉ", 'email': "địa chỉ mail", 'link': "Các trang mạng liên kết", 'summary': "Giớ thiệu công ty", } widgets = { 'avatar': forms.FileInput( attrs={ 'class': 'form-control', 'placeholder': 'Ảnh đại diện công ty', 'name': 'avatar' }), 'title': forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'Tên dịch vụ', 'name': 'title' }), 'phone': widgets.PhoneNumberPrefixWidget( attrs={ 'class': 'form-control', 'placeholder': 'Số điện thoại', 'name': 'phone' }), 'email': forms.EmailInput( attrs={ 'class': 'form-control', 'placeholder': 'Nhâp địa chỉ mail', 'name': 'email' }), 'address': forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'Phí phát sinh (tiền phạt, phí đường bộ...)', 'name': 'address' }), 'link': forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'Tiền cho thuê xe', 'name': 'link' }), 'summary': forms.Textarea( attrs={ 'class': 'form-control', 'placeholder': 'Nội dung trang web', 'name': 'summary' }), }
class Meta: model = Driver fields = [ 'idcard', 'drivername', 'phone_number', 'address', 'birthday', 'experience', 'introduce', 'avatar' ] widgets = { 'idcard': forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'Nhập chứng minh nhân dân', 'name': 'idcard' }), 'drivername': forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'Tên tài xế', 'name': 'drivername' }), 'phone_number': widgets.PhoneNumberPrefixWidget( attrs={ 'class': 'form-control', 'placeholder': 'Nhập số điện thoại', 'name': 'phone_number' }), 'address': forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'Địa chỉ thường trú', 'name': 'address' }), 'birthday': forms.DateInput(attrs={ 'id': 'datepicker', 'class': 'form-control', 'name': 'age' }), #attrs={'class': 'form-control', 'name': 'age'} 'experience': forms.NumberInput(attrs={ 'class': 'form-control', 'name': 'experience' }), #attrs={'class': 'form-control', 'name': 'experience'} 'introduce': forms.Textarea( attrs={ 'cols': 30, 'rows': 5, 'class': 'form-control', 'placeholder': 'Giới thiệu đôi chút về bản thân', 'name': 'introduce' }), 'avatar': forms.FileInput(attrs={ 'class': 'form-control', 'name': 'avatar' }), # }
def get_form(self, form_class=None): """Adds custom placeholders and widgets to the form""" form = super().get_form(form_class) form.fields['email'].widget.attrs = {'placeholder': _('Email Address')} form.fields['email'].label = _('Email') form.fields['shipping_full_name'].widget.attrs = { 'placeholder': _('Full Name')} form.fields['shipping_full_name'].label = _('Full Name') form.fields['shipping_phone_number'] = CharField( widget=widgets.PhoneNumberPrefixWidget( attrs={ 'type': 'tel', 'placeholder': _('Phone Number'), 'class': 'form-control', 'pattern': '[0-9]+', }), initial='+39') form.fields['shipping_street_address_1'].widget.attrs = { 'placeholder': _('123 Main St.')} form.fields['shipping_street_address_1'].label = _('Street Address 1') form.fields['shipping_street_address_2'].widget.attrs = { 'placeholder': _('Street Address 2')} form.fields['shipping_street_address_2'].label = _('Street Address 2') form.fields['shipping_town_or_city'].widget.attrs = { 'placeholder': _('Town or City')} form.fields['shipping_town_or_city'].label = _('Town or City') form.fields['shipping_county'].widget.attrs = { 'placeholder': _('Locality')} form.fields['shipping_county'].label = _('County, State or Locality') form.fields['shipping_country'].widget.attrs = { 'class': 'form-control'} form.fields['shipping_country'].label = _('Country') form.fields['shipping_postcode'].widget.attrs = { 'placeholder': _('Postcode')} form.fields['shipping_postcode'].label = _('Postcode') form.fields['billing_full_name'].widget.attrs = { 'placeholder': _('Full Name'), 'class': 'billing-field'} form.fields['billing_full_name'].label = _('Full Name') form.fields['billing_phone_number'] = CharField( label=_('Phone Number'), widget=widgets.PhoneNumberPrefixWidget( attrs={ 'type': 'tel', 'placeholder': _('Phone Number'), 'class': 'form-control billing-field', 'pattern': '[0-9]+', }), initial='+39') form.fields['billing_street_address_1'].widget.attrs = { 'Placeholder': _('Street Address 1'), 'class': 'billing-field'} form.fields['billing_street_address_1'].label = _('Street Address 1') form.fields['billing_street_address_2'].widget.attrs = { 'placeholder': _('Street Address 2')} form.fields['billing_street_address_2'].label = _('Street Address 2') form.fields['billing_town_or_city'].widget.attrs = { 'placeholder': _('Town or City'), 'class': 'billing-field'} form.fields['billing_town_or_city'].label = _('Town or City') form.fields['billing_county'].widget.attrs = { 'placeholder': _('Locality')} form.fields['billing_county'].label = _('County, State or Locality') form.fields['billing_country'].widget.attrs = { 'class': 'form-control billing-field'} form.fields['billing_country'].label = _('Country') form.fields['billing_postcode'].widget.attrs = { 'placeholder': _('Postcode')} form.fields['billing_postcode'].label = _('Postcode') return form
def __init__(self, *args, **kwargs): """Selects custom layout and placeholders for the form.""" super().__init__(*args, **kwargs) self.helper = FormHelper(self) helper = self.helper helper.form_action = 'users:shipping-billing' helper.form_id = 'shipping_billing_form' helper.form_tag = False self.fields['shipping_phone_number'] = forms.CharField( widget=widgets.PhoneNumberPrefixWidget(), required=False) self.fields['billing_phone_number'] = forms.CharField( widget=widgets.PhoneNumberPrefixWidget(), required=False) self.fields['shipping_full_name'].label = _('Full Name') self.fields['shipping_street_address_1'].label = _('Street Address 1') self.fields['shipping_street_address_2'].label = _('Street Address 2') self.fields['shipping_town_or_city'].label = _('Town or City') self.fields['shipping_county'].label = _('County, State or Locality') self.fields['shipping_country'].label = _('Country') self.fields['billing_full_name'].label = _('Full Name') self.fields['billing_street_address_1'].label = _('Street Address 1') self.fields['billing_street_address_2'].label = _('Street Address 2') self.fields['billing_town_or_city'].label = _('Town or City') self.fields['billing_county'].label = _('County, State or Locality') self.fields['billing_postcode'].label = _('Postcode') self.fields['billing_country'].label = _('Country') helper.layout = Layout( Row( Column( Fieldset( _('SHIPPING DETAILS'), Row( Field('shipping_full_name', placeholder=_('Full Name'), css_class='p-font text-primary'), MultiWidgetField( 'shipping_phone_number', template='bootstrap4/phone_field.html'), Field('shipping_street_address_1', placeholder=_('Street Address 1'), css_class='p-font text-primary'), Field('shipping_street_address_2', placeholder=_('Street Address 2'), css_class='p-font text-primary'), Field('shipping_town_or_city', placeholder=_('Town or City'), css_class='p-font text-primary'), Field('shipping_county', placeholder=_('County, State or Locality'), css_class='p-font text-primary'), Field('shipping_postcode', placeholder=_('Postcode'), css_class='p-font text-primary'), Field( 'shipping_country', css_class='form-select p-font text-primary'))), css_class='col-12 col-md-6 p-2 px-md-4 pt-md-4 pb-md-2'), Column( Fieldset( _('BILLING DETAILS'), Row( Field('billing_full_name', placeholder=_('Full Name'), css_class='p-font text-primary'), MultiWidgetField( 'billing_phone_number', template='bootstrap4/phone_field.html'), Field('billing_street_address_1', placeholder=_('Street Address 1'), css_class='p-font text-primary'), Field('billing_street_address_2', placeholder=_('Street Address 2'), css_class='p-font text-primary'), Field('billing_town_or_city', placeholder=_('Town or City'), css_class='p-font text-primary'), Field('billing_county', placeholder=_('County, State or Locality'), css_class='p-font text-primary'), Field('billing_postcode', placeholder=_('Postcode'), css_class='p-font text-primary'), Field( 'billing_country', css_class='form-select p-font text-primary'))), css_class='col-12 col-md-6 p-2 px-md-4 pt-md-4 pb-md-2'), Column(StrictButton( _('Save Details'), type='submit', css_class='p-font btn-tran btn btn-sm fw-bold \ btn-warning text-primary shadow'), css_class='col-12 col-md-auto ps-2 pb-2 px-md-4 \ pb-md-4 mx-md-auto')))
class SignUpForm(UserCreationForm): phone = formfields.PhoneNumberField(widget=widgets.PhoneNumberPrefixWidget(), initial='+91') class Meta: model = Account fields = ('email', 'first_name', 'last_name', 'phone') # Fields while signing up through the website