Commits

Anonymous committed 164a15d

magic-removal: Replaced __repr__() with __str__() in docs

Comments (0)

Files changed (3)

         name = models.CharField(maxlength=100)
         tagline = models.TextField()
 
-        def __repr__(self):
+        def __str__(self):
             return self.name
 
     class Author(models.Model):
         name = models.CharField(maxlength=50)
         email = models.URLField()
 
-        class __repr__(self):
+        class __str__(self):
             return self.name
 
     class Entry(models.Model):
         pub_date = models.DateTimeField()
         authors = models.ManyToManyField(Author)
 
-        def __repr__(self):
+        def __str__(self):
             return self.headline
 
 Creating objects

docs/model-api.txt

           ``short_description`` function attribute, for use as the header for
           the field.
 
-        * Use the string ``"__repr__"`` to output the representation of the
-          object, according to your model's ``__repr__()`` function. If you
-          don't define ``list_display``, Django will use the ``__repr__`` by
+        * Use the string ``"__str__"`` to output the representation of the
+          object, according to your model's ``__str__()`` function. If you
+          don't define ``list_display``, Django will use the ``__str__`` by
           default.
 
     See the example below.
 
 A few object methods have special meaning:
 
-``__repr__``
-    Django uses ``repr(obj)`` in a number of places, most notably as the value
+``__str__``
+    Django uses ``str(obj)`` in a number of places, most notably as the value
     inserted into a template when it displays an object. Thus, you should always
-    return a nice, human-readable string for the object's ``__repr__``.
+    return a nice, human-readable string for the object's ``__str__``.
 
-    Although defining ``__repr__()`` isn't required, it's strongly encouraged.
+    Although defining ``__str__()`` isn't required, it's strongly encouraged.
 
-    See `Adding repr`_ for a full example.
+    See `Adding str`_ for a full example.
 
-    .. _Adding repr: http://www.djangoproject.com/documentation/models/repr/
+    .. _Adding str: http://www.djangoproject.com/documentation/models/repr/
 
 ``get_absolute_url``
     Define a ``get_absolute_url`` method to tell Django how to calculate the

docs/tutorial01.txt

 
 Wait a minute. ``<Poll object>`` is, utterly, an unhelpful representation of
 this object. Let's fix that by editing the polls model
-(in the ``polls/models.py`` file) and adding a ``__repr__()`` method to
+(in the ``polls/models.py`` file) and adding a ``__str__()`` method to
 both ``Poll`` and ``Choice``::
 
     class Poll(models.Model):
         # ...
-        def __repr__(self):
+        def __str__(self):
             return self.question
 
     class Choice(models.Model):
         # ...
-        def __repr__(self):
+        def __str__(self):
             return self.choice
 
-It's important to add ``__repr__()`` methods to your models, not only for your
+It's important to add ``__str__()`` methods to your models, not only for your
 own sanity when dealing with the interactive prompt, but also because objects'
 representations are used throughout Django's automatically-generated admin.
 
 
     >>> from mysite.polls.models import Poll, Choice
 
-    # Make sure our __repr__() addition worked.
+    # Make sure our __str__() addition worked.
     >>> Poll.objects.all()
     [What's up?]