Commit 7442eb1a authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #20224 -- Update docs examples which mention __unicode__

Thanks Marc Tamlyn and Tim Graham for the review.
parent 577b0f91
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class Command(LabelCommand):
        make_option('--multi-geom', action='store_true', dest='multi_geom', default=False,
                    help='Treat the geometry in the data source as a geometry collection.'),
        make_option('--name-field', dest='name_field',
                    help='Specifies a field name to return for the `__unicode__` function.'),
                    help='Specifies a field name to return for the `__unicode__`/`__str__` function.'),
        make_option('--no-imports', action='store_false', dest='imports', default=True,
                    help='Do not include `from django.contrib.gis.db import models` '
                    'statement.'),
+3 −2
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ def ogrinspect(*args, **kwargs):
     `multi_geom` => Boolean (default: False) - specify as multigeometry.

     `name_field` => String - specifies a field name to return for the
       `__unicode__` function (which will be generated if specified).
       `__unicode__`/`__str__` function (which will be generated if specified).

     `imports` => Boolean (default: True) - set to False to omit the
       `from django.contrib.gis.db import models` code from the
@@ -221,4 +221,5 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non

    if name_field:
        yield ''
        yield '    def __str__(self): return self.%s' % name_field
        yield '    def __%s__(self): return self.%s' % (
            'str' if six.PY3 else 'unicode', name_field)
+3 −3
Original line number Diff line number Diff line
@@ -710,9 +710,9 @@ smoothly:
   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 automatically
   converts to the string form of your Python object, you can save yourself
   a lot of work.
   ``HandField``). So if your ``__unicode__()`` method (``__str__()`` on
   Python 3) automatically converts to the string form of your Python object,
   you can save yourself a lot of work.


Writing a ``FileField`` subclass
+4 −1
Original line number Diff line number Diff line
@@ -124,13 +124,16 @@ Model style
          first_name = models.CharField(max_length=20)
          last_name = models.CharField(max_length=40)

* If you define a ``__str__`` method (previously ``__unicode__`` before Python 3
  was supported), decorate the model class with
  :func:`~django.utils.encoding.python_2_unicode_compatible`.

* The order of model inner classes and standard methods should be as
  follows (noting that these are not all required):

  * All database fields
  * Custom manager attributes
  * ``class Meta``
  * ``def __unicode__()``
  * ``def __str__()``
  * ``def save()``
  * ``def get_absolute_url()``
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ the file ``mysite/news/models.py``::
    class Reporter(models.Model):
        full_name = models.CharField(max_length=70)

        # On Python 3: def __str__(self):
        def __unicode__(self):
            return self.full_name

@@ -40,6 +41,7 @@ the file ``mysite/news/models.py``::
        content = models.TextField()
        reporter = models.ForeignKey(Reporter)

        # On Python 3: def __str__(self):
        def __unicode__(self):
            return self.headline

Loading