-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Ticket #35831 Include ModelForm and its Meta options in reference docs, follow up on PR #18699 #19758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…k target to the ModelForm topic entry.
…y functions. Reworked text based on PR feedback.
options and Factory functions. Reworked text based on PR feedback.
Co-authored-by: Tim Schilling <schilling711@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! Thank you for your contribution 💪
As it's your first contribution be sure to check out the patch review checklist.
If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!
If you have any design or process questions then you can ask in the Django forum.
Welcome aboard ⛵️!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for picking this up @mspirbhai !
Once you have reverted the changes in docs/conf.py
, can you squash to a single commit with yourself and @jernwerber as the co-author?
I have re-read through and tried to make suggestions with the following in mind:
- consistency of phrasing
- "less is more": occasionally there were references around potential errors raised when not configured correctly. I have sometimes opted to remove this and focus on documenting how to configure correctly.
I have broken up these suggestions so if you disagree with any of the changes, shout 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert changes in this file as they do not relate to ticket-35831
.. class:: ModelForm | ||
|
||
.. _ref-modelform: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. class:: ModelForm | |
.. _ref-modelform: |
.. _ref-modelform-meta-options: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. _ref-modelform-meta-options: |
.. currentmodule:: django.forms | ||
|
||
:class:`~django.forms.ModelForm` API reference. For introductory material about | ||
ModelForms, see the :doc:`/topics/forms/modelforms` topic guide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModelForms, see the :doc:`/topics/forms/modelforms` topic guide. | |
using a ``ModelForm``, see the :doc:`/topics/forms/modelforms` topic guide. |
The ``_meta`` API is used to build forms that reflect a Django model. The API | ||
is accessible through the ``_meta`` attribute of each model form, which is an | ||
instance of a ``django.forms.models.ModelFormOptions`` object. | ||
The exact structure of the form produced can be controlled by setting metadata | ||
options as attributes of an inner ``Meta`` class. | ||
|
||
Here is an example using some sort of Book model:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ``_meta`` API is used to build forms that reflect a Django model. The API | |
is accessible through the ``_meta`` attribute of each model form, which is an | |
instance of a ``django.forms.models.ModelFormOptions`` object. | |
The exact structure of the form produced can be controlled by setting metadata | |
options as attributes of an inner ``Meta`` class. | |
Here is an example using some sort of Book model:: | |
The ``_meta`` API is used to build forms that reflect a Django model. It is | |
accessible through the ``_meta`` attribute of each model form, and is an | |
``django.forms.models.ModelFormOptions`` instance. | |
The structure of the generated form can be customized by defining metadata | |
options as attributes of an inner ``Meta`` class. For example:: |
(perhaps)
A dictionary that maps a model field name string to a help text | ||
string. | ||
|
||
Where a field doesn't have a label string mapped to it in | ||
:attr:`~ModelFormOptions.help_texts`, Django will fall back on that model | ||
field's :attr:`~django.db.models.Field.help_text`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dictionary that maps a model field name string to a help text | |
string. | |
Where a field doesn't have a label string mapped to it in | |
:attr:`~ModelFormOptions.help_texts`, Django will fall back on that model | |
field's :attr:`~django.db.models.Field.help_text`. | |
A dictionary that maps a model field name to a help text string. | |
When a field is not specified, Django will fall back on that model field's | |
:attr:`~django.db.models.Field.help_text`. |
A dictionary that maps a model field name string to a label string. | ||
|
||
Where a field doesn't have a label string mapped to it in | ||
:attr:`~ModelFormOptions.labels`, Django will fall back on that model | ||
field's :attr:`~django.db.models.Field.verbose_name` and then the field's | ||
attribute name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dictionary that maps a model field name string to a label string. | |
Where a field doesn't have a label string mapped to it in | |
:attr:`~ModelFormOptions.labels`, Django will fall back on that model | |
field's :attr:`~django.db.models.Field.verbose_name` and then the field's | |
attribute name. | |
A dictionary that maps a model field names to a label string. | |
When a field is not specified, Django will fall back on that model field's | |
:attr:`~django.db.models.Field.verbose_name` and then the field's attribute | |
name. |
A tuple of strings or a list of strings that are field names. | ||
|
||
The fields included in this list will have their data localized (by default, | ||
the form fields output by a :class:`~django.forms.ModelForm` are **not** | ||
localized, see :ref:`Creating forms from models: Enabling localization of | ||
fields <modelforms-enabling-localization-of-fields>`). | ||
|
||
Like :attr:`~ModelFormOptions.fields`, | ||
:attr:`~ModelFormOptions.localized_fields` can be set to the special string | ||
``'__all__'`` to include all fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tuple of strings or a list of strings that are field names. | |
The fields included in this list will have their data localized (by default, | |
the form fields output by a :class:`~django.forms.ModelForm` are **not** | |
localized, see :ref:`Creating forms from models: Enabling localization of | |
fields <modelforms-enabling-localization-of-fields>`). | |
Like :attr:`~ModelFormOptions.fields`, | |
:attr:`~ModelFormOptions.localized_fields` can be set to the special string | |
``'__all__'`` to include all fields. | |
A tuple or list of :attr:`~ModelFormOptions.model` field names to be | |
localized. The value ``'__all__'`` can be used to specify that all fields | |
should be localized. | |
By default, form fields are not localized, see | |
:ref:`enabling localization of fields | |
<modelforms-enabling-localization-of-fields>` for more details. |
*Required.* A :class:`django.db.models.Model` to be used for this | ||
:class:`~django.forms.ModelForm`. | ||
|
||
If no class is specified, a :exc:`ValueError` exception will be raised. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*Required.* A :class:`django.db.models.Model` to be used for this | |
:class:`~django.forms.ModelForm`. | |
If no class is specified, a :exc:`ValueError` exception will be raised. | |
Required. The :class:`django.db.models.Model` to be used for the | |
:class:`~django.forms.ModelForm`. |
A dictionary that maps a model field name string to a | ||
:class:`django.forms.Widget`. | ||
|
||
Where an included model field doesn't have a widget mapped to it in | ||
:attr:`~ModelFormOptions.widgets`, Django will fall back on the default | ||
widget for that particular type of :class:`django.db.models.Field`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dictionary that maps a model field name string to a | |
:class:`django.forms.Widget`. | |
Where an included model field doesn't have a widget mapped to it in | |
:attr:`~ModelFormOptions.widgets`, Django will fall back on the default | |
widget for that particular type of :class:`django.db.models.Field`. | |
A dictionary that maps a model field name to a | |
:class:`django.forms.Widget`. | |
When a field is not specified, Django will fall back on the default widget | |
for that particular type of :class:`django.db.models.Field`. |
Trac ticket number
ticket-35831
Branch description
Follow up on @jernwerber work on the ticket from PR #18699.
Checklist
main
branch.