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

  • Loading branch information...
commit 7cc3acbb70c8f66060b377ed402df3085288b006 1 parent 226b733
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
@@ -578,27 +578,33 @@ Wait a minute. ``<Poll: Poll object>`` is, utterly, an unhelpful representation
578 578
 of this object. Let's fix that by editing the polls model (in the
579 579
 ``polls/models.py`` file) and adding a
580 580
 :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
  582
+following example::
582 583
 
583 584
     class Poll(models.Model):
584 585
         # ...
585  
-        def __unicode__(self):
  586
+        def __unicode__(self):  # Python 3: def __str__(self):
586 587
             return self.question
587 588
 
588 589
     class Choice(models.Model):
589 590
         # ...
590  
-        def __unicode__(self):
  591
+        def __unicode__(self):  # Python 3: def __str__(self):
591 592
             return self.choice_text
592 593
 
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.
  594
+It'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
  596
+for your own sanity when dealing with the interactive prompt, but also because
  597
+objects' representations are used throughout Django's automatically-generated
  598
+admin.
597 599
 
598  
-.. admonition:: Why :meth:`~django.db.models.Model.__unicode__` and not
  600
+.. admonition:: :meth:`~django.db.models.Model.__unicode__` or
599 601
                 :meth:`~django.db.models.Model.__str__`?
600 602
 
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
602 608
     :meth:`~django.db.models.Model.__str__` methods to your classes, not
603 609
     :meth:`~django.db.models.Model.__unicode__` methods. We use
604 610
     :meth:`~django.db.models.Model.__unicode__` here because Django models deal

0 notes on commit 7cc3acb

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