9
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",}
- [Django]-Python Asyncio in Django View
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-Is there an easy way to populate SlugField from CharField?
6
After add help_texts in form, you should do smth like this in a frontend:
<label title="{{ form.name.help_text }}" for="{{ form.name.id_for_label }}">Your label</label>
{{ form.name }} {{ form.quantity }}
- [Django]-How to get form fields' id in Django
- [Django]-Create a field whose value is a calculation of other fields' values
- [Django]-How can I find the union of two Django querysets?
4
By ‘detail page’ you mean a edit form of a single student instance or the list of all student records?
Are you using Django admin or do you use your own view and template, custom form definition or as_ul()/as_list() etc?
It’s hard to answer your question with just seeing your form field definition.
What do you mean by ‘for each table’?
Would form inheritance help, so that you set the help text of common form fields only in the super form.
If you render a custom template you can render the help_text wherever you like with
{{ my_field.help_text }}. If you have a table-like view in your template and want the helptext there, just put an empty instance of the form in your template context so that you have access to the help_texts and put it in your table as tooltip?
- [Django]-Tailwindcss: fixed/sticky footer on the bottom
- [Django]-How to convert a Django QuerySet to a list?
- [Django]-STATIC_ROOT vs STATIC_URL in Django
1
In case you want to use the standard admin change form with a short help-text for each field but sometimes feel the need to give a longer explanation or even a table with some sample values (without restricting the user to a predefined set of choices) you can do something like this:
my_strange_field = models.FloatField('strange parameter', validators=[MinValueValidator(1.0)],
help_text='corr. factor x >= 1 <img src="/static/admin/img/icon-unknown.gif" '
'width="15" height="15" title="typical values:\n'
'cow:\t2..3\ncat:\t5..7\ndog:\t11..15')
This way you get a short text “corr. factor x >= 1” followed by a nifty question mark which presents a table like tool-tip without the need to modify the change_form template.
- [Django]-DRY way to add created/modified by and time
- [Django]-Import error django corsheaders
- [Django]-Custom validation in Django admin