Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19211 -- Adapted tutorial for Python 3

Backport of 7cc3acb from master.
  • Loading branch information...
commit 406fd9f97f4b04212276e2e78d8216ef5a27a514 1 parent 8f4552a
Claude Paroz authored April 22, 2013

Showing 1 changed file with 15 additions and 9 deletions. Show diff stats Hide diff stats

  1. 24  docs/intro/tutorial01.txt
24  docs/intro/tutorial01.txt
@@ -589,27 +589,33 @@ Wait a minute. ``<Poll: Poll object>`` is, utterly, an unhelpful representation
589 589
 of this object. Let's fix that by editing the polls model (in the
590 590
 ``polls/models.py`` file) and adding a
591 591
 :meth:`~django.db.models.Model.__unicode__` method to both ``Poll`` and
592  
-``Choice``::
  592
+``Choice``. On Python 3, simply replace ``__unicode__`` by ``__str__`` in the
  593
+following example::
593 594
 
594 595
     class Poll(models.Model):
595 596
         # ...
596  
-        def __unicode__(self):
  597
+        def __unicode__(self):  # Python 3: def __str__(self):
597 598
             return self.question
598 599
 
599 600
     class Choice(models.Model):
600 601
         # ...
601  
-        def __unicode__(self):
  602
+        def __unicode__(self):  # Python 3: def __str__(self):
602 603
             return self.choice_text
603 604
 
604  
-It's important to add :meth:`~django.db.models.Model.__unicode__` methods to
605  
-your models, not only for your own sanity when dealing with the interactive
606  
-prompt, but also because objects' representations are used throughout Django's
607  
-automatically-generated admin.
  605
+It's important to add :meth:`~django.db.models.Model.__unicode__` methods (or
  606
+:meth:`~django.db.models.Model.__str__` on Python 3) to your models, not only
  607
+for your own sanity when dealing with the interactive prompt, but also because
  608
+objects' representations are used throughout Django's automatically-generated
  609
+admin.
608 610
 
609  
-.. admonition:: Why :meth:`~django.db.models.Model.__unicode__` and not
  611
+.. admonition:: :meth:`~django.db.models.Model.__unicode__` or
610 612
                 :meth:`~django.db.models.Model.__str__`?
611 613
 
612  
-    If you're familiar with Python, you might be in the habit of adding
  614
+    On Python 3, things are simpler, just use
  615
+    :meth:`~django.db.models.Model.__str__` and forget about
  616
+    :meth:`~django.db.models.Model.__unicode__`.
  617
+
  618
+    If you're familiar with Python 2, you might be in the habit of adding
613 619
     :meth:`~django.db.models.Model.__str__` methods to your classes, not
614 620
     :meth:`~django.db.models.Model.__unicode__` methods. We use
615 621
     :meth:`~django.db.models.Model.__unicode__` here because Django models deal

0 notes on commit 406fd9f

Please sign in to comment.
Something went wrong with that request. Please try again.