Loading docs/howto/custom-model-fields.txt +3 −3 Original line number Diff line number Diff line Loading @@ -817,13 +817,13 @@ smoothly: a field that's similar to what you want and extend it a little bit, instead of creating an entirely new field from scratch. 2. Put a ``__str__()`` or ``__unicode__()`` method on the class you're 2. Put a ``__str__()`` (``__unicode__()`` on Python 2) method on the class you're wrapping up as a field. There are a lot of places where the default behavior of the field code is to call :func:`~django.utils.encoding.force_text` on the value. (In our examples in this document, ``value`` would be a ``Hand`` instance, not a ``HandField``). So if your ``__unicode__()`` method (``__str__()`` on Python 3) automatically converts to the string form of your Python object, ``HandField``). So if your ``__str__()`` method (``__unicode__()`` on Python 2) automatically converts to the string form of your Python object, you can save yourself a lot of work. Loading docs/intro/tutorial01.txt +1 −1 Original line number Diff line number Diff line Loading @@ -727,7 +727,7 @@ Save these changes and start a new Python interactive shell by running >>> from polls.models import Question, Choice # Make sure our __unicode__() addition worked. # Make sure our __str__() addition worked. >>> Question.objects.all() [<Question: What's up?>] Loading docs/ref/contrib/admin/actions.txt +1 −2 Original line number Diff line number Diff line Loading @@ -57,8 +57,7 @@ simple news application with an ``Article`` model:: body = models.TextField() status = models.CharField(max_length=1, choices=STATUS_CHOICES) # On Python 3: def __str__(self): def __unicode__(self): def __str__(self): # __unicode__ on Python 2 return self.title A common task we might perform with a model like this is to update an Loading docs/ref/contrib/admin/index.txt +6 −6 Original line number Diff line number Diff line Loading @@ -512,7 +512,7 @@ subclass:: list_display = ('first_name', 'last_name') If you don't set ``list_display``, the admin site will display a single column that displays the ``__unicode__()`` (``__str__()`` on Python 3) column that displays the ``__str__()`` (``__unicode__()`` on Python 2) representation of each object. You have four possible values that can be used in ``list_display``: Loading Loading @@ -563,7 +563,7 @@ subclass:: A few special cases to note about ``list_display``: * If the field is a ``ForeignKey``, Django will display the ``__unicode__()`` (``__str__()`` on Python 3) of the related object. ``__str__()`` (``__unicode__()`` on Python 2) of the related object. * ``ManyToManyField`` fields aren't supported, because that would entail executing a separate SQL statement for each row in the table. Loading Loading @@ -626,11 +626,11 @@ subclass:: list_display = ('name', 'born_in_fifties') * The ``__str__()`` and ``__unicode__()`` methods are just as valid in ``list_display`` as any other model method, so it's perfectly OK to do this:: * The ``__str__()`` (``__unicode__()`` on Python 2) method is just as valid in ``list_display`` as any other model method, so it's perfectly OK to do this:: list_display = ('__unicode__', 'some_other_field') list_display = ('__str__', 'some_other_field') * Usually, elements of ``list_display`` that aren't actual database fields can't be used in sorting (because Django does all the sorting Loading docs/ref/contrib/contenttypes.txt +1 −2 Original line number Diff line number Diff line Loading @@ -259,8 +259,7 @@ A simple example is a tagging system, which might look like this:: object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') # On Python 3: def __str__(self): def __unicode__(self): def __str__(self): # __unicode__ on Python 2 return self.tag A normal :class:`~django.db.models.ForeignKey` can only "point Loading Loading
docs/howto/custom-model-fields.txt +3 −3 Original line number Diff line number Diff line Loading @@ -817,13 +817,13 @@ smoothly: a field that's similar to what you want and extend it a little bit, instead of creating an entirely new field from scratch. 2. Put a ``__str__()`` or ``__unicode__()`` method on the class you're 2. Put a ``__str__()`` (``__unicode__()`` on Python 2) method on the class you're wrapping up as a field. There are a lot of places where the default behavior of the field code is to call :func:`~django.utils.encoding.force_text` on the value. (In our examples in this document, ``value`` would be a ``Hand`` instance, not a ``HandField``). So if your ``__unicode__()`` method (``__str__()`` on Python 3) automatically converts to the string form of your Python object, ``HandField``). So if your ``__str__()`` method (``__unicode__()`` on Python 2) automatically converts to the string form of your Python object, you can save yourself a lot of work. Loading
docs/intro/tutorial01.txt +1 −1 Original line number Diff line number Diff line Loading @@ -727,7 +727,7 @@ Save these changes and start a new Python interactive shell by running >>> from polls.models import Question, Choice # Make sure our __unicode__() addition worked. # Make sure our __str__() addition worked. >>> Question.objects.all() [<Question: What's up?>] Loading
docs/ref/contrib/admin/actions.txt +1 −2 Original line number Diff line number Diff line Loading @@ -57,8 +57,7 @@ simple news application with an ``Article`` model:: body = models.TextField() status = models.CharField(max_length=1, choices=STATUS_CHOICES) # On Python 3: def __str__(self): def __unicode__(self): def __str__(self): # __unicode__ on Python 2 return self.title A common task we might perform with a model like this is to update an Loading
docs/ref/contrib/admin/index.txt +6 −6 Original line number Diff line number Diff line Loading @@ -512,7 +512,7 @@ subclass:: list_display = ('first_name', 'last_name') If you don't set ``list_display``, the admin site will display a single column that displays the ``__unicode__()`` (``__str__()`` on Python 3) column that displays the ``__str__()`` (``__unicode__()`` on Python 2) representation of each object. You have four possible values that can be used in ``list_display``: Loading Loading @@ -563,7 +563,7 @@ subclass:: A few special cases to note about ``list_display``: * If the field is a ``ForeignKey``, Django will display the ``__unicode__()`` (``__str__()`` on Python 3) of the related object. ``__str__()`` (``__unicode__()`` on Python 2) of the related object. * ``ManyToManyField`` fields aren't supported, because that would entail executing a separate SQL statement for each row in the table. Loading Loading @@ -626,11 +626,11 @@ subclass:: list_display = ('name', 'born_in_fifties') * The ``__str__()`` and ``__unicode__()`` methods are just as valid in ``list_display`` as any other model method, so it's perfectly OK to do this:: * The ``__str__()`` (``__unicode__()`` on Python 2) method is just as valid in ``list_display`` as any other model method, so it's perfectly OK to do this:: list_display = ('__unicode__', 'some_other_field') list_display = ('__str__', 'some_other_field') * Usually, elements of ``list_display`` that aren't actual database fields can't be used in sorting (because Django does all the sorting Loading
docs/ref/contrib/contenttypes.txt +1 −2 Original line number Diff line number Diff line Loading @@ -259,8 +259,7 @@ A simple example is a tagging system, which might look like this:: object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') # On Python 3: def __str__(self): def __unicode__(self): def __str__(self): # __unicode__ on Python 2 return self.tag A normal :class:`~django.db.models.ForeignKey` can only "point Loading