Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change help text of a django form field?

This is my model for a group message which extends another model Message which has some other fields like text, time, etc.

class GroupMessage(Message):     group = models.ForeignKey(Group, related_name='+') 

Following is the form I've created for this model.

class GroupForm(ModelForm):     class Meta:         model = GroupMessage 

How do I change help text of group field in my form? Any help would be appreciated.

like image 823
Sudhanshu Mishra Avatar asked Jun 21 '14 19:06

Sudhanshu Mishra


People also ask

What is help text in django?

help_text attribute is used to display the “help” text along with the field in form in admin interface or ModelForm. It's useful for documentation even if your field isn't used on a form. For example, you can define the pattern of date to be taken as input in the help_text of DateField.

How do I add an admin to text in django?

help_text = 'My help text' class Meta: model = MyModel exclude = () @admin. register(MyModel) class MyModelAdmin(admin. ModelAdmin): form = MyForm # ... Show activity on this post.

How do I override a django form?

You can override forms for django's built-in admin by setting form attribute of ModelAdmin to your own form class. See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form.

What is form Is_valid () in django?

The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.


1 Answers

For Django >= 1.6 (docs):

class GroupForm(ModelForm):     class Meta:         model = GroupMessage         help_texts = {             'group': 'Group to which this message belongs to',         } 
like image 180
laffuste Avatar answered Sep 19 '22 16:09

laffuste