From a83236560ea90e3dc457d215322b55db8ee16c7d Mon Sep 17 00:00:00 2001 From: 1wos <1wosomm1@gmail.com> Date: Sat, 25 Apr 2026 21:47:33 +0900 Subject: [PATCH] Fixed #27825 -- Doc'd that setting model fields does not convert types. Co-authored-by: Jacob Walls --- AUTHORS | 1 + docs/ref/models/instances.txt | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/AUTHORS b/AUTHORS index 8182862607e8..a752a2e0e892 100644 --- a/AUTHORS +++ b/AUTHORS @@ -991,6 +991,7 @@ answer newbie questions, and generally made Django that much better: Slawek Mikula sloonz smurf@smurf.noris.de + Somi Jeong sopel Sreehari K V Sridhar Marella diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 716cb48b4c5d..8b9fb1aff4a0 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -68,6 +68,16 @@ need to :meth:`~Model.save`. book = Book.objects.create_book("Pride and Prejudice") +.. admonition:: Setting attributes does not convert types + + Setting a model attribute does not convert the value to the field's Python + type. That conversion happens when the model is :ref:`validated + `. Although a field assigned a value of a different + type (for example, a string assigned to a + :class:`~django.db.models.UUIDField`) may be converted when + :meth:`~Model.save` executes a query, the in-memory instance will keep the + original value until it is :ref:`reloaded `. + Customizing model loading ------------------------- @@ -131,6 +141,8 @@ The example above shows a full ``from_db()`` implementation to clarify how that is done. In this case it would be possible to use a ``super()`` call in the ``from_db()`` method. +.. _refreshing-objects: + Refreshing objects from database ================================