Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i add help text in django model fields

I have a Student detail page where I have all the student data shown in a log nested format.

Now in the form I know I can add a help text. But now my manager wants that when we show the detail page, there should be help on hovering over each field.

Now I am confused where should I enter 50-100 words help text for each table in 5-6 tables

This is how I used help_text in the forms:

student_number = forms.CharField(         required=False, max_length=64, label='Student Number',         help_text='Unique identifier for the student ') 
like image 981
user26 Avatar asked Aug 12 '13 01:08

user26


People also ask

How do I add text to Django model?

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 create a text field in Django?

For example, adding an argument null = True to TextField will enable it to store empty values for that table in relational database. Here are the field options and attributes that an TextField can use. If True, Django will store empty values as NULL in the database. Default is False.

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.


2 Answers

Yes you can! Just like your form, you can add help_text to your model fields.

like image 61
nim4n Avatar answered Sep 22 '22 16:09

nim4n


When using model forms you can add labels and help_texts to fields generated by the model. see docs

class PupilForm(forms.ModelForm):    class Meta:     model = Pupil      fields = ['student_number',]     labels = {'student_number': "Student Number",}     help_texts = {'student_number': "Unique identifier for the student",} 
like image 20
tomcounsell Avatar answered Sep 25 '22 16:09

tomcounsell