Ticket #19211: 19211.diff

File 19211.diff, 2.2 KB (added by claudep, 2 years ago)

Adapt tutorial for Python 3

  • docs/intro/tutorial01.txt

    diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt
    index 55e85dc..7c21041 100644
    a b Wait a minute. ``<Poll: Poll object>`` is, utterly, an unhelpful representation 
    578578of this object. Let's fix that by editing the polls model (in the
    579579``polls/models.py`` file) and adding a
    580580:meth:`~django.db.models.Model.__unicode__` method to both ``Poll`` and
    581 ``Choice``::
     581``Choice``. On Python 3, simply replace ``__unicode__`` by ``__str__`` in the
     582following example::
    582583
    583584    class Poll(models.Model):
    584585        # ...
    585         def __unicode__(self):
     586        def __unicode__(self):  # Python 3: def __str__(self):
    586587            return self.question
    587588
    588589    class Choice(models.Model):
    589590        # ...
    590         def __unicode__(self):
     591        def __unicode__(self):  # Python 3: def __str__(self):
    591592            return self.choice_text
    592593
    593 It's important to add :meth:`~django.db.models.Model.__unicode__` methods to
    594 your models, not only for your own sanity when dealing with the interactive
    595 prompt, but also because objects' representations are used throughout Django's
    596 automatically-generated admin.
     594It's important to add :meth:`~django.db.models.Model.__unicode__` methods (or
     595:meth:`~django.db.models.Model.__str__` on Python 3) to your models, not only
     596for your own sanity when dealing with the interactive prompt, but also because
     597objects' representations are used throughout Django's automatically-generated
     598admin.
    597599
    598 .. admonition:: Why :meth:`~django.db.models.Model.__unicode__` and not
     600.. admonition:: :meth:`~django.db.models.Model.__unicode__` or
    599601                :meth:`~django.db.models.Model.__str__`?
    600602
    601     If you're familiar with Python, you might be in the habit of adding
     603    On Python 3, things are simpler, just use
     604    :meth:`~django.db.models.Model.__str__` and forget about
     605    :meth:`~django.db.models.Model.__unicode__`.
     606
     607    If you're familiar with Python 2, you might be in the habit of adding
    602608    :meth:`~django.db.models.Model.__str__` methods to your classes, not
    603609    :meth:`~django.db.models.Model.__unicode__` methods. We use
    604610    :meth:`~django.db.models.Model.__unicode__` here because Django models deal
Back to Top