Ticket #4814: tutorial01.diff

File tutorial01.diff, 1.6 KB (added by John Shaffer <jshaffer2112@…>, 13 years ago)

Replace tabs with spaces and reformat to 80 columns

  • tutorial01.txt

     
    494494
    495495.. admonition:: Why ``__unicode__()`` and not ``__str__()``?
    496496
    497         If you're familiar with Python, you might be in the habit of adding
    498         ``__str__()`` methods to your classes, not ``__unicode__()`` methods.
     497    If you're familiar with Python, you might be in the habit of adding
     498    ``__str__()`` methods to your classes, not ``__unicode__()`` methods.
    499499    We use ``__unicode__()`` here because Django models deal with Unicode by
    500500    default. All data stored in your database is converted to Unicode when it's
    501501    returned.
    502502
    503         Django models have a default ``__str__()`` method that calls ``__unicode__()``
    504         and converts the result to a UTF-8 bytestring. This means that ``unicode(p)``
    505         will return a Unicode string, and ``str(p)`` will return a normal string,
    506         with characters encoded as UTF-8.
     503    Django models have a default ``__str__()`` method that calls
     504    ``__unicode__()`` and converts the result to a UTF-8 bytestring. This means
     505    that ``unicode(p)`` will return a Unicode string, and ``str(p)`` will return
     506    a normal string, with characters encoded as UTF-8.
    507507
    508         If all of this is jibberish to you, just remember to add ``__unicode__()``
    509         methods to your models. With any luck, things should Just Work for you.
     508    If all of this is jibberish to you, just remember to add ``__unicode__()``
     509    methods to your models. With any luck, things should Just Work for you.
    510510
    511511Note these are normal Python methods. Let's add a custom method, just for
    512512demonstration::
Back to Top