From 0ebea6e5c07485a36862e9b6e2be18d1694ad2c5 Mon Sep 17 00:00:00 2001 From: Clifford Gama Date: Sat, 8 Mar 2025 15:46:58 +0200 Subject: Fixed #35676 -- Made BaseModelForm validate constraints that reference an InlineForeignKeyField. Co-authored-by: Simon Charette --- docs/topics/forms/modelforms.txt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'docs') diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index e2a37296b7..ef916d882d 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -242,9 +242,13 @@ when calling :meth:`~django.forms.Form.is_valid()` or accessing the ``full_clean()``, although you will typically not use the latter method in practice. -``Model`` validation (:meth:`Model.full_clean() -`) is triggered from within the form -validation step, right after the form's ``clean()`` method is called. +``Model`` validation is triggered from within the form validation step right +after the form's ``clean()`` method is called. First, the model's +:meth:`~django.db.models.Model.full_clean()` is called with +``validate_unique=False`` and ``validate_constraints=False``, then the model's +:meth:`~django.db.models.Model.validate_unique()` and +:meth:`~django.db.models.Model.validate_constraints()` methods are called in +order. .. warning:: @@ -267,10 +271,10 @@ attribute that gives its methods access to that specific model instance. .. warning:: - The ``ModelForm.clean()`` method sets a flag that makes the :ref:`model + The ``ModelForm.clean()`` method sets flags that make the :ref:`model validation ` step validate the uniqueness of model fields that are marked as ``unique``, ``unique_together`` or - ``unique_for_date|month|year``. + ``unique_for_date|month|year``, as well as constraints. If you would like to override the ``clean()`` method and maintain this validation, you must call the parent class's ``clean()`` method. @@ -284,9 +288,9 @@ If you have excluded any model fields, validation will not be run on those fields. See the :doc:`form validation ` documentation for more on how field cleaning and validation work. -The model's ``clean()`` method will be called before any uniqueness checks are -made. See :ref:`Validating objects ` for more information -on the model's ``clean()`` hook. +The model's ``clean()`` method will be called before any uniqueness or +constraint checks are made. See :ref:`Validating objects ` +for more information on the model's ``clean()`` hook. .. _considerations-regarding-model-errormessages: -- cgit v1.3