Changeset 2795
- Timestamp:
- 04/29/06 22:42:53 (2 years ago)
- Files:
-
- django/branches/magic-removal/docs/db-api.txt (modified) (3 diffs)
- django/branches/magic-removal/docs/model-api.txt (modified) (2 diffs)
- django/branches/magic-removal/docs/tutorial01.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/docs/db-api.txt
r2773 r2795 16 16 tagline = models.TextField() 17 17 18 def __ repr__(self):18 def __str__(self): 19 19 return self.name 20 20 … … 23 23 email = models.URLField() 24 24 25 class __ repr__(self):25 class __str__(self): 26 26 return self.name 27 27 … … 33 33 authors = models.ManyToManyField(Author) 34 34 35 def __ repr__(self):35 def __str__(self): 36 36 return self.headline 37 37 django/branches/magic-removal/docs/model-api.txt
r2772 r2795 967 967 the field. 968 968 969 * Use the string ``"__ repr__"`` to output the representation of the970 object, according to your model's ``__ repr__()`` function. If you971 don't define ``list_display``, Django will use the ``__ repr__`` by969 * 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 972 972 default. 973 973 … … 1132 1132 A few object methods have special meaning: 1133 1133 1134 ``__ repr__``1135 Django uses `` repr(obj)`` in a number of places, most notably as the value1134 ``__str__`` 1135 Django uses ``str(obj)`` in a number of places, most notably as the value 1136 1136 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/ 1144 1144 1145 1145 ``get_absolute_url`` django/branches/magic-removal/docs/tutorial01.txt
r2776 r2795 457 457 Wait a minute. ``<Poll object>`` is, utterly, an unhelpful representation of 458 458 this object. Let's fix that by editing the polls model 459 (in the ``polls/models.py`` file) and adding a ``__ repr__()`` method to459 (in the ``polls/models.py`` file) and adding a ``__str__()`` method to 460 460 both ``Poll`` and ``Choice``:: 461 461 462 462 class Poll(models.Model): 463 463 # ... 464 def __ repr__(self):464 def __str__(self): 465 465 return self.question 466 466 467 467 class Choice(models.Model): 468 468 # ... 469 def __ repr__(self):469 def __str__(self): 470 470 return self.choice 471 471 472 It's important to add ``__ repr__()`` methods to your models, not only for your472 It's important to add ``__str__()`` methods to your models, not only for your 473 473 own sanity when dealing with the interactive prompt, but also because objects' 474 474 representations are used throughout Django's automatically-generated admin. … … 492 492 >>> from mysite.polls.models import Poll, Choice 493 493 494 # Make sure our __ repr__() addition worked.494 # Make sure our __str__() addition worked. 495 495 >>> Poll.objects.all() 496 496 [What's up?]
