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.
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.
help_text = 'My help text' class Meta: model = MyModel exclude = () @admin. register(MyModel) class MyModelAdmin(admin. ModelAdmin): form = MyForm # ... Show activity on this post.
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.
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.
For Django >= 1.6 (docs):
class GroupForm(ModelForm): class Meta: model = GroupMessage help_texts = { 'group': 'Group to which this message belongs to', }
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