3

I have a model in model.py and I generate a model form in inventory_form.py.

A field is named watercourse in my model and the form field is labelled Watercourse.

model.py

class Inventory(models.Model): watercourse = models.CharField(max_length=255, null=False) 

inventory_form.py

class InventoryModelForm(forms.ModelForm): class Meta: model = Inventory fields = ['watercourse',] widgets = { 'watercourse': forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'lorem ipsum', }), } 

How do I change the label to Insert a watercourse?

3 Answers 3

9

Within the AuthorForm class you can set the labels attribute which is a dictionary maps field name to label.

class InventoryModelForm(forms.ModelForm): class Meta: model = Inventory fields = ['watercourse',] widgets = { 'watercourse': forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'lorem ipsum', }), } labels = { 'watercourse': 'Insert a watercourse', } 
Sign up to request clarification or add additional context in comments.

Comments

1

you can do this:

class Meta:

labels = { 'name': 'LabelName', } 

Comments

0

In forms.py try

labels = { 'name': _('Writer'), } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.