
I'm working through https://bixly.com/blog/awesome-forms-django-crispy-forms/ , trying to set up a bootstrap 3 form using django crispy forms.
in app1/models.py, I have set up my form:
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
from django import forms
class User(AbstractUser):
# Address
contact_name = models.CharField(max_length=50)
contact_address = models.CharField(max_length=50)
contact_email = models.CharField(max_length=50)
contact_phone = models.CharField(max_length=50)
......
In app1/forms.py I have:
class UserForm(forms.ModelForm):
class Meta:
model = User # Your User model
fields = ['contact_name', 'contact_address', 'contact_email', 'contact_phone']
helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Submit', 'Submit', css_class='btn-primary'))
Right now, the label is the same as the field name. How can I set the label to something different. Example for 'contact_name' the label might ask 'What is your name?'
Try to use the labels meta-field
Like:
class UserForm(forms.ModelForm):
class Meta:
model = User # Your User model
fields = ['contact_name', 'contact_address', 'contact_email', 'contact_phone']
labels = {
'contact_name': 'What is your name',
}
helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Submit', 'Submit', css_class='btn-primary'))
where contact_name is the name of the field, and 'What is your name' is the output to show
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With