Fixed #4814 -- Fixed some whitespace issues in tutorial01, thanks John Shaffer.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5639 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0be6d32c24
commit
541c9ff797
|
@ -494,19 +494,19 @@ admin.
|
||||||
|
|
||||||
.. admonition:: Why ``__unicode__()`` and not ``__str__()``?
|
.. admonition:: Why ``__unicode__()`` and not ``__str__()``?
|
||||||
|
|
||||||
If you're familiar with Python, you might be in the habit of adding
|
If you're familiar with Python, you might be in the habit of adding
|
||||||
``__str__()`` methods to your classes, not ``__unicode__()`` methods.
|
``__str__()`` methods to your classes, not ``__unicode__()`` methods.
|
||||||
We use ``__unicode__()`` here because Django models deal with Unicode by
|
We use ``__unicode__()`` here because Django models deal with Unicode by
|
||||||
default. All data stored in your database is converted to Unicode when it's
|
default. All data stored in your database is converted to Unicode when it's
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
Django models have a default ``__str__()`` method that calls ``__unicode__()``
|
Django models have a default ``__str__()`` method that calls
|
||||||
and converts the result to a UTF-8 bytestring. This means that ``unicode(p)``
|
``__unicode__()`` and converts the result to a UTF-8 bytestring. This means
|
||||||
will return a Unicode string, and ``str(p)`` will return a normal string,
|
that ``unicode(p)`` will return a Unicode string, and ``str(p)`` will return
|
||||||
with characters encoded as UTF-8.
|
a normal string, with characters encoded as UTF-8.
|
||||||
|
|
||||||
If all of this is jibberish to you, just remember to add ``__unicode__()``
|
If all of this is jibberish to you, just remember to add ``__unicode__()``
|
||||||
methods to your models. With any luck, things should Just Work for you.
|
methods to your models. With any luck, things should Just Work for you.
|
||||||
|
|
||||||
Note these are normal Python methods. Let's add a custom method, just for
|
Note these are normal Python methods. Let's add a custom method, just for
|
||||||
demonstration::
|
demonstration::
|
||||||
|
|
Loading…
Reference in New Issue