Skip to content

Commit a832365

Browse files
1wosjacobtylerwalls
andcommitted
Fixed #27825 -- Doc'd that setting model fields does not convert types.
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
1 parent 9f44c94 commit a832365

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ answer newbie questions, and generally made Django that much better:
991991
Slawek Mikula <slawek dot mikula at gmail dot com>
992992
sloonz <simon.lipp@insa-lyon.fr>
993993
smurf@smurf.noris.de
994+
Somi Jeong <https://github.com/1wos>
994995
sopel
995996
Sreehari K V <sreeharivijayan619@gmail.com>
996997
Sridhar Marella <sridhar562345@gmail.com>

docs/ref/models/instances.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ need to :meth:`~Model.save`.
6868

6969
book = Book.objects.create_book("Pride and Prejudice")
7070

71+
.. admonition:: Setting attributes does not convert types
72+
73+
Setting a model attribute does not convert the value to the field's Python
74+
type. That conversion happens when the model is :ref:`validated
75+
<validating-objects>`. Although a field assigned a value of a different
76+
type (for example, a string assigned to a
77+
:class:`~django.db.models.UUIDField`) may be converted when
78+
:meth:`~Model.save` executes a query, the in-memory instance will keep the
79+
original value until it is :ref:`reloaded <refreshing-objects>`.
80+
7181
Customizing model loading
7282
-------------------------
7383

@@ -131,6 +141,8 @@ The example above shows a full ``from_db()`` implementation to clarify how that
131141
is done. In this case it would be possible to use a ``super()`` call in the
132142
``from_db()`` method.
133143

144+
.. _refreshing-objects:
145+
134146
Refreshing objects from database
135147
================================
136148

0 commit comments

Comments
 (0)