mirror of
https://github.com/django/django.git
synced 2025-08-27 05:54:28 +00:00
Fixed #21951 -- Updated docs to use __str__ for Python 3
Thanks Tim Graham for the report and recommendations
This commit is contained in:
parent
c3434fed5b
commit
8aa1efff6d
20 changed files with 71 additions and 72 deletions
|
@ -817,13 +817,13 @@ smoothly:
|
|||
a field that's similar to what you want and extend it a little bit,
|
||||
instead of creating an entirely new field from scratch.
|
||||
|
||||
2. Put a ``__str__()`` or ``__unicode__()`` method on the class you're
|
||||
2. Put a ``__str__()`` (``__unicode__()`` on Python 2) method on the class you're
|
||||
wrapping up as a field. There are a lot of places where the default
|
||||
behavior of the field code is to call
|
||||
:func:`~django.utils.encoding.force_text` on the value. (In our
|
||||
examples in this document, ``value`` would be a ``Hand`` instance, not a
|
||||
``HandField``). So if your ``__unicode__()`` method (``__str__()`` on
|
||||
Python 3) automatically converts to the string form of your Python object,
|
||||
``HandField``). So if your ``__str__()`` method (``__unicode__()`` on
|
||||
Python 2) automatically converts to the string form of your Python object,
|
||||
you can save yourself a lot of work.
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue