Django

Code

Changeset 2795

Show
Ignore:
Timestamp:
04/29/06 22:42:53 (2 years ago)
Author:
adrian
Message:

magic-removal: Replaced repr() with str() in docs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/docs/db-api.txt

    r2773 r2795  
    1616        tagline = models.TextField() 
    1717 
    18         def __repr__(self): 
     18        def __str__(self): 
    1919            return self.name 
    2020 
     
    2323        email = models.URLField() 
    2424 
    25         class __repr__(self): 
     25        class __str__(self): 
    2626            return self.name 
    2727 
     
    3333        authors = models.ManyToManyField(Author) 
    3434 
    35         def __repr__(self): 
     35        def __str__(self): 
    3636            return self.headline 
    3737 
  • django/branches/magic-removal/docs/model-api.txt

    r2772 r2795  
    967967          the field. 
    968968 
    969         * Use the string ``"__repr__"`` to output the representation of the 
    970           object, according to your model's ``__repr__()`` function. If you 
    971           don't define ``list_display``, Django will use the ``__repr__`` by 
     969        * Use the string ``"__str__"`` to output the representation of the 
     970          object, according to your model's ``__str__()`` function. If you 
     971          don't define ``list_display``, Django will use the ``__str__`` by 
    972972          default. 
    973973 
     
    11321132A few object methods have special meaning: 
    11331133 
    1134 ``__repr__`` 
    1135     Django uses ``repr(obj)`` in a number of places, most notably as the value 
     1134``__str__`` 
     1135    Django uses ``str(obj)`` in a number of places, most notably as the value 
    11361136    inserted into a template when it displays an object. Thus, you should always 
    1137     return a nice, human-readable string for the object's ``__repr__``. 
    1138  
    1139     Although defining ``__repr__()`` isn't required, it's strongly encouraged. 
    1140  
    1141     See `Adding repr`_ for a full example. 
    1142  
    1143     .. _Adding repr: http://www.djangoproject.com/documentation/models/repr/ 
     1137    return a nice, human-readable string for the object's ``__str__``. 
     1138 
     1139    Although defining ``__str__()`` isn't required, it's strongly encouraged. 
     1140 
     1141    See `Adding str`_ for a full example. 
     1142 
     1143    .. _Adding str: http://www.djangoproject.com/documentation/models/repr/ 
    11441144 
    11451145``get_absolute_url`` 
  • django/branches/magic-removal/docs/tutorial01.txt

    r2776 r2795  
    457457Wait a minute. ``<Poll object>`` is, utterly, an unhelpful representation of 
    458458this object. Let's fix that by editing the polls model 
    459 (in the ``polls/models.py`` file) and adding a ``__repr__()`` method to 
     459(in the ``polls/models.py`` file) and adding a ``__str__()`` method to 
    460460both ``Poll`` and ``Choice``:: 
    461461 
    462462    class Poll(models.Model): 
    463463        # ... 
    464         def __repr__(self): 
     464        def __str__(self): 
    465465            return self.question 
    466466 
    467467    class Choice(models.Model): 
    468468        # ... 
    469         def __repr__(self): 
     469        def __str__(self): 
    470470            return self.choice 
    471471 
    472 It's important to add ``__repr__()`` methods to your models, not only for your 
     472It's important to add ``__str__()`` methods to your models, not only for your 
    473473own sanity when dealing with the interactive prompt, but also because objects' 
    474474representations are used throughout Django's automatically-generated admin. 
     
    492492    >>> from mysite.polls.models import Poll, Choice 
    493493 
    494     # Make sure our __repr__() addition worked. 
     494    # Make sure our __str__() addition worked. 
    495495    >>> Poll.objects.all() 
    496496    [What's up?]