Skip to content

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

mspirbhai
Copy link

Trac ticket number

ticket-35831

Branch description

Follow up on @jernwerber work on the ticket from PR #18699.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

Copy link

@github-actions github-actions bot left a 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 ⛵️!

Copy link
Contributor

@sarahboyce sarahboyce left a 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 👍

Copy link
Contributor

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

Comment on lines +9 to +12
.. class:: ModelForm

.. _ref-modelform:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. class:: ModelForm
.. _ref-modelform:

Comment on lines +18 to +19
.. _ref-modelform-meta-options:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. _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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ModelForms, see the :doc:`/topics/forms/modelforms` topic guide.
using a ``ModelForm``, see the :doc:`/topics/forms/modelforms` topic guide.

Comment on lines +25 to +31
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::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Comment on lines +180 to +185
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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.

Comment on lines +192 to +197
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +204 to +213
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +220 to +223
*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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*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`.

Comment on lines +230 to +235
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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants