Custom label in Django Formset
How to add custom labels to my form set?
<form method="post" action=""> {{ formset.management_form }} {% for form in formset %} {% for field in form %} {{ field.label_tag }}: {{ field }} {% endfor %} {% endfor %} </form> My model:
class Sing(models.Model): song = models.CharField(max_length = 50) band = models.CharField(max_length = 50) Now in the template instead of the label for the 'song' field, how can I set it so that it appears as 'What song are you going to sing?' ?
You can use the label argument in your form:
class MySingForm(forms.Form): song = forms.CharField(label='What song are you going to sing?') ... If you are using ModelForms :
class MySingForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(MySingForm, self).__init__(*args, **kwargs) self.fields['song'].label = 'What song are you going to sing?' class Meta: model = Sing Update:
(comment by Daniel Rosemann)
Or in the model (using verbose_name ):
class Sing(models.Model): song = models.CharField(verbose_name='What song are you going to sing?', max_length=50) ... or
class Sing(models.Model): song = models.CharField('What song are you going to sing?', max_length=50) ...