1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #20224 -- Update docs examples which mention __unicode__

Thanks Marc Tamlyn and Tim Graham for the review.
This commit is contained in:
Claude Paroz
2013-07-04 15:19:33 +02:00
parent 577b0f9189
commit 7442eb1a24
24 changed files with 65 additions and 24 deletions

View File

@@ -430,6 +430,12 @@ Other model instance methods
A few object methods have special purposes.
.. note::
On Python 3, as all strings are natively considered Unicode, only use the
``__str__()`` method (the ``__unicode__()`` method is obsolete).
If you'd like compatibility with Python 2, you can decorate your model class
with :func:`~django.utils.encoding.python_2_unicode_compatible`.
``__unicode__``
---------------

View File

@@ -814,6 +814,7 @@ For example, suppose you have these models::
name = models.CharField(max_length=50)
toppings = models.ManyToManyField(Topping)
# On Python 3: def __str__(self):
def __unicode__(self):
return u"%s (%s)" % (self.name, u", ".join([topping.name
for topping in self.toppings.all()]))