Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixed #20224 -- Update docs examples which mention __unicode__ #1330

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Member

claudep commented Jul 4, 2013

No description provided.

@mjtamlyn mjtamlyn commented on the diff Jul 4, 2013

.../internals/contributing/writing-code/coding-style.txt
@@ -124,13 +124,16 @@ Model style
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=40)
+* If you define a ``__str__`` method (previously ``__unicode__`` before Python 3
@mjtamlyn

mjtamlyn Jul 4, 2013

Member

This comment and the one above are worded differently. It would be nice to have consistency.

@claudep

claudep Jul 4, 2013

Member

Marc, I'm sorry but I'm not getting your idea here.

@mjtamlyn

mjtamlyn Jul 5, 2013

Member

Almost every place in the documentation we say "__unicode__ (or __str__ on Py3)". In this case we mention it the other way around. It's a minor point, and I guess actually as this is in the contributing docs it's a bit different. I hadn't noticed this was in contributing docs earlier which may be a bit different to user facing docs.

Member

mjtamlyn commented Jul 4, 2013

So, when are we dropping 2.7? 😉

@timgraham timgraham commented on the diff Jul 4, 2013

docs/howto/custom-model-fields.txt
@@ -696,9 +696,9 @@ smoothly:
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 automatically
- converts to the string form of your Python object, you can save yourself
- a lot of work.
+ ``HandField``). So if your ``__unicode__()`` method (``__str__`` on Python 3)
@timgraham

timgraham Jul 4, 2013

Owner

add () on str for consistency with "unicode()"

@timgraham timgraham commented on the diff Jul 4, 2013

docs/ref/models/instances.txt
@@ -430,6 +430,12 @@ Other model instance methods
A few object methods have special purposes.
+.. note::
+ On Python 3, as all strings are natively considered Unicode, only use the
+ ``__str__()`` method, which entirely obsoletes the ``__unicode__()`` method.
@timgraham

timgraham Jul 4, 2013

Owner

I'd replace

", which entirely obsoletes the ``__unicode__()`` method"

with

"(the __unicode__()`` method is obsolete)"

@timgraham timgraham commented on the diff Jul 4, 2013

docs/topics/db/examples/many_to_one.txt
@@ -56,9 +58,9 @@ Article objects have access to their related Reporter objects::
>>> r = a.reporter
-These are strings instead of unicode strings because that's what was used in
-the creation of this reporter (and we haven't refreshed the data from the
-database, which always returns unicode strings)::
+On Python 2, these are strings instead of unicode strings because that's what
@timgraham

timgraham Jul 4, 2013

Owner

maybe add: strings of type str

@claudep claudep closed this Jul 5, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment