Kaydet (Commit) 4c35a173 authored tarafından Srinivas Reddy Thatiparthy's avatar Srinivas Reddy Thatiparthy Kaydeden (comit) Tim Graham

Fixed #29423 -- Documented Field.value_from_object().

üst 738a0a4d
...@@ -679,8 +679,8 @@ Converting field data for serialization ...@@ -679,8 +679,8 @@ Converting field data for serialization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To customize how the values are serialized by a serializer, you can override To customize how the values are serialized by a serializer, you can override
:meth:`~Field.value_to_string`. Using ``value_from_object()`` is the best way :meth:`~Field.value_to_string`. Using :meth:`~Field.value_from_object` is the
to get the field's value prior to serialization. For example, since our best way to get the field's value prior to serialization. For example, since
``HandField`` uses strings for its data storage anyway, we can reuse some ``HandField`` uses strings for its data storage anyway, we can reuse some
existing conversion code:: existing conversion code::
......
...@@ -1857,6 +1857,12 @@ Field API reference ...@@ -1857,6 +1857,12 @@ Field API reference
Besides saving to the database, the field also needs to know how to Besides saving to the database, the field also needs to know how to
serialize its value: serialize its value:
.. method:: value_from_object(obj)
Returns the field's value for the given model instance.
This method is often used by :meth:`value_to_string`.
.. method:: value_to_string(obj) .. method:: value_to_string(obj)
Converts ``obj`` to a string. Used to serialize the value of the field. Converts ``obj`` to a string. Used to serialize the value of the field.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment