Author: mtredinnick
Date: 2007-05-30 23:25:40 -0500 (Wed, 30 May 2007)
New Revision: 5386

Modified:
   django/branches/unicode/docs/db-api.txt
   django/branches/unicode/docs/forms.txt
   django/branches/unicode/docs/model-api.txt
   django/branches/unicode/docs/newforms.txt
   django/branches/unicode/docs/overview.txt
   django/branches/unicode/docs/tutorial01.txt
   django/branches/unicode/tests/modeltests/basic/models.py
   django/branches/unicode/tests/modeltests/choices/models.py
   django/branches/unicode/tests/modeltests/custom_columns/models.py
   django/branches/unicode/tests/modeltests/custom_managers/models.py
   django/branches/unicode/tests/modeltests/custom_methods/models.py
   django/branches/unicode/tests/modeltests/custom_pk/models.py
   django/branches/unicode/tests/modeltests/field_defaults/models.py
   django/branches/unicode/tests/modeltests/fixtures/models.py
   django/branches/unicode/tests/modeltests/generic_relations/models.py
   django/branches/unicode/tests/modeltests/get_latest/models.py
   django/branches/unicode/tests/modeltests/get_object_or_404/models.py
   django/branches/unicode/tests/modeltests/get_or_create/models.py
   django/branches/unicode/tests/modeltests/lookup/models.py
   django/branches/unicode/tests/modeltests/m2m_and_m2o/models.py
   django/branches/unicode/tests/modeltests/m2m_intermediary/models.py
   django/branches/unicode/tests/modeltests/m2m_multiple/models.py
   django/branches/unicode/tests/modeltests/m2m_recursive/models.py
   django/branches/unicode/tests/modeltests/m2o_recursive/models.py
   django/branches/unicode/tests/modeltests/m2o_recursive2/models.py
   django/branches/unicode/tests/modeltests/manipulators/models.py
   django/branches/unicode/tests/modeltests/many_to_many/models.py
   django/branches/unicode/tests/modeltests/many_to_one/models.py
   django/branches/unicode/tests/modeltests/many_to_one_null/models.py
   django/branches/unicode/tests/modeltests/model_forms/models.py
   django/branches/unicode/tests/modeltests/model_inheritance/models.py
   django/branches/unicode/tests/modeltests/one_to_one/models.py
   django/branches/unicode/tests/modeltests/or_lookups/models.py
   django/branches/unicode/tests/modeltests/ordering/models.py
   django/branches/unicode/tests/modeltests/pagination/models.py
   django/branches/unicode/tests/modeltests/reserved_names/models.py
   django/branches/unicode/tests/modeltests/reverse_lookup/models.py
   django/branches/unicode/tests/modeltests/save_delete_hooks/models.py
   django/branches/unicode/tests/modeltests/select_related/models.py
   django/branches/unicode/tests/modeltests/serializers/models.py
   django/branches/unicode/tests/modeltests/str/models.py
   django/branches/unicode/tests/modeltests/transactions/models.py
   django/branches/unicode/tests/modeltests/validation/models.py
   django/branches/unicode/tests/regressiontests/fixtures_regress/models.py
   django/branches/unicode/tests/regressiontests/null_queries/models.py
   django/branches/unicode/tests/regressiontests/one_to_one_regress/models.py
Log:
unicode: Changed all tests and documentation to use __unicode__ instead of
__str__ in places where it's appropriate to do so.


Modified: django/branches/unicode/docs/db-api.txt
===================================================================
--- django/branches/unicode/docs/db-api.txt     2007-05-31 02:22:41 UTC (rev 
5385)
+++ django/branches/unicode/docs/db-api.txt     2007-05-31 04:25:40 UTC (rev 
5386)
@@ -15,14 +15,14 @@
         name = models.CharField(maxlength=100)
         tagline = models.TextField()
 
-        def __str__(self):
+        def __unicode__(self):
             return self.name
 
     class Author(models.Model):
         name = models.CharField(maxlength=50)
         email = models.URLField()
 
-        def __str__(self):
+        def __unicode__(self):
             return self.name
 
     class Entry(models.Model):
@@ -32,7 +32,7 @@
         pub_date = models.DateTimeField()
         authors = models.ManyToManyField(Author)
 
-        def __str__(self):
+        def __unicode__(self):
             return self.headline
 
 Creating objects

Modified: django/branches/unicode/docs/forms.txt
===================================================================
--- django/branches/unicode/docs/forms.txt      2007-05-31 02:22:41 UTC (rev 
5385)
+++ django/branches/unicode/docs/forms.txt      2007-05-31 04:25:40 UTC (rev 
5386)
@@ -47,7 +47,7 @@
         class Admin:
             pass
 
-        def __str__(self):
+        def __unicode__(self):
             return self.name
 
 Defining the above class is enough to create an admin interface to a ``Place``,

Modified: django/branches/unicode/docs/model-api.txt
===================================================================
--- django/branches/unicode/docs/model-api.txt  2007-05-31 02:22:41 UTC (rev 
5385)
+++ django/branches/unicode/docs/model-api.txt  2007-05-31 04:25:40 UTC (rev 
5386)
@@ -1339,10 +1339,11 @@
               born_in_fifties.boolean = True
 
 
-    * The ``__str__()`` method is just as valid in ``list_display`` as any
-      other model method, so it's perfectly OK to do this::
+    * 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::
 
-          list_display = ('__str__', 'some_other_field')
+          list_display = ('__unicode__', '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 at the
@@ -1748,11 +1749,13 @@
 -----------
 
 ``__str__()`` is a Python "magic method" that defines what should be returned
-if you call ``str()`` on the object. Django uses ``str(obj)`` in a number of
-places, most notably as the value displayed to render an object in the Django
-admin site and as the value inserted into a template when it displays an
-object. Thus, you should always return a nice, human-readable string for the
-object's ``__str__``. Although this isn't required, it's strongly encouraged.
+if you call ``str()`` on the object. Django uses ``str(obj)`` (or the related
+function, ``unicode(obj)`` -- see below) in a number of places, most notably
+as the value displayed to render an object in the Django admin site and as the
+value inserted into a template when it displays an object. Thus, you should
+always return a nice, human-readable string for the object's ``__str__``.
+Although this isn't required, it's strongly encouraged (see the description of
+``__unicode__``, below, before putting ``_str__`` methods everywhere).
 
 For example::
 
@@ -1761,8 +1764,33 @@
         last_name = models.CharField(maxlength=50)
 
         def __str__(self):
-            return '%s %s' % (self.first_name, self.last_name)
+            # Note use of django.utils.encoding.smart_str() here because
+            # first_name and last_name will be unicode strings.
+            return smart_str('%s %s' % (self.first_name, self.last_name))
 
+``__unicode__``
+---------------
+
+The ``__unicode__()`` method is called whenever you call ``unicode()`` on an
+object. Since Django's database backends will return Unicode strings in your
+model's attributes, you would normally want to write a ``__unicode__()``
+method for your model. The example in the previous section could be written
+more simply as::
+
+    class Person(models.Model):
+        first_name = models.CharField(maxlength=50)
+        last_name = models.CharField(maxlength=50)
+
+        def __unicode__(self):
+            return u'%s %s' % (self.first_name, self.last_name)
+
+If you define a ``__unicode__()`` method on your model and not a ``__str__()``
+method, Django will automatically provide you with a ``__str__()`` that calls
+``__unicode()__`` and then converts the result correctly to a UTF-8 encoded
+string object. This is recommended development practice: define only
+``__unicode__()`` and let Django take care of the conversion to string objects
+when required.
+
 ``get_absolute_url``
 --------------------
 

Modified: django/branches/unicode/docs/newforms.txt
===================================================================
--- django/branches/unicode/docs/newforms.txt   2007-05-31 02:22:41 UTC (rev 
5385)
+++ django/branches/unicode/docs/newforms.txt   2007-05-31 04:25:40 UTC (rev 
5386)
@@ -1333,7 +1333,7 @@
         title = models.CharField(maxlength=3, choices=TITLE_CHOICES)
         birth_date = models.DateField(blank=True, null=True)
 
-        def __str__(self):
+        def __unicode__(self):
             return self.name
 
     class Book(models.Model):

Modified: django/branches/unicode/docs/overview.txt
===================================================================
--- django/branches/unicode/docs/overview.txt   2007-05-31 02:22:41 UTC (rev 
5385)
+++ django/branches/unicode/docs/overview.txt   2007-05-31 04:25:40 UTC (rev 
5386)
@@ -27,7 +27,7 @@
     class Reporter(models.Model):
         full_name = models.CharField(maxlength=70)
 
-        def __str__(self):
+        def __unicode__(self):
             return self.full_name
 
     class Article(models.Model):
@@ -36,7 +36,7 @@
         article = models.TextField()
         reporter = models.ForeignKey(Reporter)
 
-        def __str__(self):
+        def __unicode__(self):
             return self.headline
 
 Install it

Modified: django/branches/unicode/docs/tutorial01.txt
===================================================================
--- django/branches/unicode/docs/tutorial01.txt 2007-05-31 02:22:41 UTC (rev 
5385)
+++ django/branches/unicode/docs/tutorial01.txt 2007-05-31 04:25:40 UTC (rev 
5386)
@@ -474,23 +474,39 @@
 
 Wait a minute. ``<Poll: Poll object>`` is, utterly, an unhelpful
 representation of this object. Let's fix that by editing the polls model (in
-the ``polls/models.py`` file) and adding a ``__str__()`` method to both
+the ``polls/models.py`` file) and adding a ``__unicode__()`` method to both
 ``Poll`` and ``Choice``::
 
     class Poll(models.Model):
         # ...
-        def __str__(self):
+        def __unicode__(self):
             return self.question
 
     class Choice(models.Model):
         # ...
-        def __str__(self):
+        def __unicode__(self):
             return self.choice
 
-It's important to add ``__str__()`` methods to your models, not only for your
-own sanity when dealing with the interactive prompt, but also because objects'
-representations are used throughout Django's automatically-generated admin.
+It's important to add ``__unicode__()`` methods to your models, not only for
+your own sanity when dealing with the interactive prompt, but also because
+objects' representations are used throughout Django's automatically-generated
+admin.
 
+.. admonition:: Why ``__unicode__`` and not ``__str__``?
+
+    If you are wondering why we add a ``__unicode__()`` method, rather than a
+    simple ``__str__()`` method, it is because Django models will contain
+    unicode strings by default. The values returned from the database, for
+    example, are all unicode strings. In most cases, your code should be
+    prepared to handle non-ASCII characters and this is a litle fiddly in
+    ``__str__()`` methods, since you have to worry about which encoding to
+    use, amongst other things. If you create a ``__unicode__()`` method,
+    Django will provide a ``__str__()`` method that calls your
+    ``__unicode__()`` and then converts the result to UTF-8 strings when
+    required. So ``unicode(p)`` will return a unicode string and ``str(p)``
+    will return a normal string, with the characters encoded as UTF-8 when
+    necessary..
+
 Note these are normal Python methods. Let's add a custom method, just for
 demonstration::
 
@@ -509,7 +525,7 @@
 
     >>> from mysite.polls.models import Poll, Choice
 
-    # Make sure our __str__() addition worked.
+    # Make sure our __unicode__() addition worked.
     >>> Poll.objects.all()
     [<Poll: What's up?>]
 

Modified: django/branches/unicode/tests/modeltests/basic/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/basic/models.py    2007-05-31 
02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/basic/models.py    2007-05-31 
04:25:40 UTC (rev 5386)
@@ -14,7 +14,7 @@
     class Meta:
         ordering = ('pub_date','headline')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS': """

Modified: django/branches/unicode/tests/modeltests/choices/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/choices/models.py  2007-05-31 
02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/choices/models.py  2007-05-31 
04:25:40 UTC (rev 5386)
@@ -20,7 +20,7 @@
     name = models.CharField(maxlength=20)
     gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/custom_columns/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/custom_columns/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/custom_columns/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -21,8 +21,8 @@
     first_name = models.CharField(maxlength=30, db_column='firstname')
     last_name = models.CharField(maxlength=30, db_column='last')
 
-    def __str__(self):
-        return '%s %s' % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u'%s %s' % (self.first_name, self.last_name)
 
     class Meta:
         db_table = 'my_author_table'
@@ -32,7 +32,7 @@
     headline = models.CharField(maxlength=100)
     authors = models.ManyToManyField(Author, db_table='my_m2m_table')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
     class Meta:

Modified: django/branches/unicode/tests/modeltests/custom_managers/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/custom_managers/models.py  
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/custom_managers/models.py  
2007-05-31 04:25:40 UTC (rev 5386)
@@ -23,8 +23,8 @@
     fun = models.BooleanField()
     objects = PersonManager()
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
 # An example of a custom manager that sets get_query_set().
 
@@ -39,7 +39,7 @@
     published_objects = PublishedBookManager()
     authors = models.ManyToManyField(Person, related_name='books')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.title
 
 # An example of providing multiple custom managers.
@@ -55,7 +55,7 @@
     cars = models.Manager()
     fast_cars = FastCarManager()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/custom_methods/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/custom_methods/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/custom_methods/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -11,7 +11,7 @@
     headline = models.CharField(maxlength=100)
     pub_date = models.DateField()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
     def was_published_today(self):

Modified: django/branches/unicode/tests/modeltests/custom_pk/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/custom_pk/models.py        
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/custom_pk/models.py        
2007-05-31 04:25:40 UTC (rev 5386)
@@ -15,8 +15,8 @@
     class Meta:
         ordering = ('last_name', 'first_name')
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
 class Business(models.Model):
     name = models.CharField(maxlength=20, primary_key=True)
@@ -24,7 +24,7 @@
     class Meta:
         verbose_name_plural = 'businesses'
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/field_defaults/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/field_defaults/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/field_defaults/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -16,7 +16,7 @@
     headline = models.CharField(maxlength=100, default='Default headline')
     pub_date = models.DateTimeField(default=datetime.now)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/fixtures/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/fixtures/models.py 2007-05-31 
02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/fixtures/models.py 2007-05-31 
04:25:40 UTC (rev 5386)
@@ -14,7 +14,7 @@
     headline = models.CharField(maxlength=100, default='Default headline')
     pub_date = models.DateTimeField()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
     class Meta:

Modified: django/branches/unicode/tests/modeltests/generic_relations/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/generic_relations/models.py        
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/generic_relations/models.py        
2007-05-31 04:25:40 UTC (rev 5386)
@@ -24,7 +24,7 @@
     class Meta:
         ordering = ["tag"]
     
-    def __str__(self):
+    def __unicode__(self):
         return self.tag
 
 class Animal(models.Model):
@@ -33,7 +33,7 @@
     
     tags = generic.GenericRelation(TaggedItem)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.common_name
         
 class Vegetable(models.Model):
@@ -42,7 +42,7 @@
     
     tags = generic.GenericRelation(TaggedItem)
     
-    def __str__(self):
+    def __unicode__(self):
         return self.name
     
 class Mineral(models.Model):
@@ -51,7 +51,7 @@
     
     # note the lack of an explicit GenericRelation here...
     
-    def __str__(self):
+    def __unicode__(self):
         return self.name
         
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/get_latest/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/get_latest/models.py       
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/get_latest/models.py       
2007-05-31 04:25:40 UTC (rev 5386)
@@ -17,7 +17,7 @@
     class Meta:
         get_latest_by = 'pub_date'
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 class Person(models.Model):
@@ -26,7 +26,7 @@
 
     # Note that this model doesn't have "get_latest_by" set.
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/get_object_or_404/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/get_object_or_404/models.py        
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/get_object_or_404/models.py        
2007-05-31 04:25:40 UTC (rev 5386)
@@ -17,7 +17,7 @@
 class Author(models.Model):
     name = models.CharField(maxlength=50)
     
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class ArticleManager(models.Manager):
@@ -30,7 +30,7 @@
     objects = models.Manager()
     by_a_sir = ArticleManager()
     
-    def __str__(self):
+    def __unicode__(self):
         return self.title
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/get_or_create/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/get_or_create/models.py    
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/get_or_create/models.py    
2007-05-31 04:25:40 UTC (rev 5386)
@@ -12,8 +12,8 @@
     last_name = models.CharField(maxlength=100)
     birthday = models.DateField()
 
-    def __str__(self):
-        return '%s %s' % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u'%s %s' % (self.first_name, self.last_name)
 
 __test__ = {'API_TESTS':"""
 # Acting as a divine being, create an Person.

Modified: django/branches/unicode/tests/modeltests/lookup/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/lookup/models.py   2007-05-31 
02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/lookup/models.py   2007-05-31 
04:25:40 UTC (rev 5386)
@@ -12,7 +12,7 @@
     class Meta:
         ordering = ('-pub_date', 'headline')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':r"""

Modified: django/branches/unicode/tests/modeltests/m2m_and_m2o/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/m2m_and_m2o/models.py      
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/m2m_and_m2o/models.py      
2007-05-31 04:25:40 UTC (rev 5386)
@@ -14,8 +14,8 @@
     cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
     client = models.ForeignKey(User, related_name='test_issue_client')
 
-    def __str__(self):
-        return str(self.num)
+    def __unicode__(self):
+        return unicode(self.num)
 
     class Meta:
         ordering = ('num',)

Modified: django/branches/unicode/tests/modeltests/m2m_intermediary/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/m2m_intermediary/models.py 
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/m2m_intermediary/models.py 
2007-05-31 04:25:40 UTC (rev 5386)
@@ -16,14 +16,14 @@
     first_name = models.CharField(maxlength=30)
     last_name = models.CharField(maxlength=30)
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
 class Article(models.Model):
     headline = models.CharField(maxlength=100)
     pub_date = models.DateField()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 class Writer(models.Model):
@@ -31,8 +31,8 @@
     article = models.ForeignKey(Article)
     position = models.CharField(maxlength=100)
 
-    def __str__(self):
-        return '%s (%s)' % (self.reporter, self.position)
+    def __unicode__(self):
+        return u'%s (%s)' % (self.reporter, self.position)
 
 __test__ = {'API_TESTS':"""
 # Create a few Reporters.

Modified: django/branches/unicode/tests/modeltests/m2m_multiple/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/m2m_multiple/models.py     
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/m2m_multiple/models.py     
2007-05-31 04:25:40 UTC (rev 5386)
@@ -14,7 +14,7 @@
     class Meta:
        ordering = ('name',)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Article(models.Model):
@@ -25,7 +25,7 @@
     class Meta:
        ordering = ('pub_date',)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/m2m_recursive/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/m2m_recursive/models.py    
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/m2m_recursive/models.py    
2007-05-31 04:25:40 UTC (rev 5386)
@@ -19,7 +19,7 @@
     friends = models.ManyToManyField('self')
     idols = models.ManyToManyField('self', symmetrical=False, 
related_name='stalkers')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/m2o_recursive/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/m2o_recursive/models.py    
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/m2o_recursive/models.py    
2007-05-31 04:25:40 UTC (rev 5386)
@@ -16,7 +16,7 @@
     name = models.CharField(maxlength=20)
     parent = models.ForeignKey('self', null=True, related_name='child_set')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/m2o_recursive2/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/m2o_recursive2/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/m2o_recursive2/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -14,7 +14,7 @@
     mother = models.ForeignKey('self', null=True, 
related_name='mothers_child_set')
     father = models.ForeignKey('self', null=True, 
related_name='fathers_child_set')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.full_name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/manipulators/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/manipulators/models.py     
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/manipulators/models.py     
2007-05-31 04:25:40 UTC (rev 5386)
@@ -10,15 +10,15 @@
     first_name = models.CharField(maxlength=30)
     last_name = models.CharField(maxlength=30)
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
 class Album(models.Model):
     name = models.CharField(maxlength=100)
     musician = models.ForeignKey(Musician)
     release_date = models.DateField(blank=True, null=True)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/many_to_many/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/many_to_many/models.py     
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/many_to_many/models.py     
2007-05-31 04:25:40 UTC (rev 5386)
@@ -12,7 +12,7 @@
 class Publication(models.Model):
     title = models.CharField(maxlength=30)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.title
 
     class Meta:
@@ -22,7 +22,7 @@
     headline = models.CharField(maxlength=100)
     publications = models.ManyToManyField(Publication)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
     class Meta:

Modified: django/branches/unicode/tests/modeltests/many_to_one/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/many_to_one/models.py      
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/many_to_one/models.py      
2007-05-31 04:25:40 UTC (rev 5386)
@@ -11,15 +11,15 @@
     last_name = models.CharField(maxlength=30)
     email = models.EmailField()
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
 class Article(models.Model):
     headline = models.CharField(maxlength=100)
     pub_date = models.DateField()
     reporter = models.ForeignKey(Reporter)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
     class Meta:

Modified: django/branches/unicode/tests/modeltests/many_to_one_null/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/many_to_one_null/models.py 
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/many_to_one_null/models.py 
2007-05-31 04:25:40 UTC (rev 5386)
@@ -10,7 +10,7 @@
 class Reporter(models.Model):
     name = models.CharField(maxlength=30)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Article(models.Model):
@@ -20,7 +20,7 @@
     class Meta:
         ordering = ('headline',)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/model_forms/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/model_forms/models.py      
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/model_forms/models.py      
2007-05-31 04:25:40 UTC (rev 5386)
@@ -34,13 +34,13 @@
     name = models.CharField(maxlength=20)
     url = models.CharField('The URL', maxlength=40)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Writer(models.Model):
     name = models.CharField(maxlength=50, help_text='Use both first and last 
names.')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Article(models.Model):
@@ -58,14 +58,14 @@
             self.created = datetime.date.today()
         return super(Article, self).save()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 class PhoneNumber(models.Model):
     phone = models.PhoneNumberField()
     description = models.CharField(maxlength=20)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.phone
 
 __test__ = {'API_TESTS': """

Modified: django/branches/unicode/tests/modeltests/model_inheritance/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/model_inheritance/models.py        
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/model_inheritance/models.py        
2007-05-31 04:25:40 UTC (rev 5386)
@@ -10,21 +10,21 @@
     name = models.CharField(maxlength=50)
     address = models.CharField(maxlength=80)
 
-    def __str__(self):
-        return "%s the place" % self.name
+    def __unicode__(self):
+        return u"%s the place" % self.name
 
 class Restaurant(Place):
     serves_hot_dogs = models.BooleanField()
     serves_pizza = models.BooleanField()
 
-    def __str__(self):
-        return "%s the restaurant" % self.name
+    def __unicode__(self):
+        return u"%s the restaurant" % self.name
 
 class ItalianRestaurant(Restaurant):
     serves_gnocchi = models.BooleanField()
 
-    def __str__(self):
-        return "%s the italian restaurant" % self.name
+    def __unicode__(self):
+        return u"%s the italian restaurant" % self.name
 
 __test__ = {'API_TESTS':"""
 # Make sure Restaurant has the right fields in the right order.

Modified: django/branches/unicode/tests/modeltests/one_to_one/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/one_to_one/models.py       
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/one_to_one/models.py       
2007-05-31 04:25:40 UTC (rev 5386)
@@ -12,23 +12,23 @@
     name = models.CharField(maxlength=50)
     address = models.CharField(maxlength=80)
 
-    def __str__(self):
-        return "%s the place" % self.name
+    def __unicode__(self):
+        return u"%s the place" % self.name
 
 class Restaurant(models.Model):
     place = models.OneToOneField(Place)
     serves_hot_dogs = models.BooleanField()
     serves_pizza = models.BooleanField()
 
-    def __str__(self):
-        return "%s the restaurant" % self.place.name
+    def __unicode__(self):
+        return u"%s the restaurant" % self.place.name
 
 class Waiter(models.Model):
     restaurant = models.ForeignKey(Restaurant)
     name = models.CharField(maxlength=50)
 
-    def __str__(self):
-        return "%s the waiter at %s" % (self.name, self.restaurant)
+    def __unicode__(self):
+        return u"%s the waiter at %s" % (self.name, self.restaurant)
 
 class ManualPrimaryKey(models.Model):
     primary_key = models.CharField(maxlength=10, primary_key=True)

Modified: django/branches/unicode/tests/modeltests/or_lookups/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/or_lookups/models.py       
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/or_lookups/models.py       
2007-05-31 04:25:40 UTC (rev 5386)
@@ -20,7 +20,7 @@
     class Meta:
        ordering = ('pub_date',)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/ordering/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/ordering/models.py 2007-05-31 
02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/ordering/models.py 2007-05-31 
04:25:40 UTC (rev 5386)
@@ -21,7 +21,7 @@
     class Meta:
         ordering = ('-pub_date', 'headline')
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/pagination/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/pagination/models.py       
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/pagination/models.py       
2007-05-31 04:25:40 UTC (rev 5386)
@@ -12,7 +12,7 @@
     headline = models.CharField(maxlength=100, default='Default headline')
     pub_date = models.DateTimeField()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/reserved_names/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/reserved_names/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/reserved_names/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -21,7 +21,7 @@
     class Meta:
        db_table = 'select'
 
-    def __str__(self):
+    def __unicode__(self):
         return self.when
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/reverse_lookup/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/reverse_lookup/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/reverse_lookup/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -9,14 +9,14 @@
 class User(models.Model):
     name = models.CharField(maxlength=200)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Poll(models.Model):
     question = models.CharField(maxlength=200)
     creator = models.ForeignKey(User)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.question
 
 class Choice(models.Model):
@@ -24,7 +24,7 @@
     poll = models.ForeignKey(Poll, related_name="poll_choice")
     related_poll = models.ForeignKey(Poll, related_name="related_choice")
 
-    def __str(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: django/branches/unicode/tests/modeltests/save_delete_hooks/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/save_delete_hooks/models.py        
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/save_delete_hooks/models.py        
2007-05-31 04:25:40 UTC (rev 5386)
@@ -11,8 +11,8 @@
     first_name = models.CharField(maxlength=20)
     last_name = models.CharField(maxlength=20)
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
     def save(self):
         print "Before save"

Modified: django/branches/unicode/tests/modeltests/select_related/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/select_related/models.py   
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/select_related/models.py   
2007-05-31 04:25:40 UTC (rev 5386)
@@ -13,49 +13,49 @@
 
 class Domain(models.Model):
     name = models.CharField(maxlength=50)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Kingdom(models.Model):
     name = models.CharField(maxlength=50)
     domain = models.ForeignKey(Domain)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Phylum(models.Model):
     name = models.CharField(maxlength=50)
     kingdom = models.ForeignKey(Kingdom)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
     
 class Klass(models.Model):
     name = models.CharField(maxlength=50)
     phylum = models.ForeignKey(Phylum)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
     
 class Order(models.Model):
     name = models.CharField(maxlength=50)
     klass = models.ForeignKey(Klass)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Family(models.Model):
     name = models.CharField(maxlength=50)
     order = models.ForeignKey(Order)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Genus(models.Model):
     name = models.CharField(maxlength=50)
     family = models.ForeignKey(Family)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Species(models.Model):
     name = models.CharField(maxlength=50)
     genus = models.ForeignKey(Genus)
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 def create_tree(stringtree):

Modified: django/branches/unicode/tests/modeltests/serializers/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/serializers/models.py      
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/serializers/models.py      
2007-05-31 04:25:40 UTC (rev 5386)
@@ -13,7 +13,7 @@
     class Meta:
        ordering = ('name',)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Author(models.Model):
@@ -22,7 +22,7 @@
     class Meta:
         ordering = ('name',)
     
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 class Article(models.Model):
@@ -34,15 +34,15 @@
     class Meta:
        ordering = ('pub_date',)
 
-    def __str__(self):
+    def __unicode__(self):
         return self.headline
 
 class AuthorProfile(models.Model):
     author = models.OneToOneField(Author)
     date_of_birth = models.DateField()
     
-    def __str__(self):
-        return "Profile of %s" % self.author
+    def __unicode__(self):
+        return u"Profile of %s" % self.author
 
 __test__ = {'API_TESTS':"""
 # Create some data:

Modified: django/branches/unicode/tests/modeltests/str/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/str/models.py      2007-05-31 
02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/str/models.py      2007-05-31 
04:25:40 UTC (rev 5386)
@@ -2,24 +2,27 @@
 """
 2. Adding __str__() or __unicode__() to models
 
-Although it's not a strict requirement, each model should have a ``__str__()``
-method to return a "human-readable" representation of the object. Do this not
-only for your own sanity when dealing with the interactive prompt, but also
-because objects' representations are used throughout Django's
-automatically-generated admin.
+Although it's not a strict requirement, each model should have a
+``_str__()`` or ``__unicode__()`` method to return a "human-readable"
+representation of the object. Do this not only for your own sanity when dealing
+with the interactive prompt, but also because objects' representations are used
+throughout Django's automatically-generated admin.
 
-For international applications, you should write ``__unicode__``() method
-instead.
+Normally,  you should write ``__unicode__``() method, since this will work for
+all field types (and Django will automatically provide an appropriate
+``__str__()`` method). However, you can write a ``__str__()`` method directly,
+if you prefer. You must be careful to encode the results correctly, though.
 """
 
 from django.db import models
+from django.utils.encoding import smart_str
 
 class Article(models.Model):
     headline = models.CharField(maxlength=100)
     pub_date = models.DateTimeField()
 
     def __str__(self):
-        return self.headline
+        return smart_str(self.headline)
 
 class InternationalArticle(models.Model):
     headline = models.CharField(maxlength=100)

Modified: django/branches/unicode/tests/modeltests/transactions/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/transactions/models.py     
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/transactions/models.py     
2007-05-31 04:25:40 UTC (rev 5386)
@@ -14,8 +14,8 @@
     last_name = models.CharField(maxlength=30)
     email = models.EmailField()
 
-    def __str__(self):
-        return "%s %s" % (self.first_name, self.last_name)
+    def __unicode__(self):
+        return u"%s %s" % (self.first_name, self.last_name)
 
 __test__ = {'API_TESTS':"""
 >>> from django.db import connection, transaction
@@ -96,4 +96,4 @@
 Traceback (most recent call last):
     ...
 TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK
-"""
\ No newline at end of file
+"""

Modified: django/branches/unicode/tests/modeltests/validation/models.py
===================================================================
--- django/branches/unicode/tests/modeltests/validation/models.py       
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/modeltests/validation/models.py       
2007-05-31 04:25:40 UTC (rev 5386)
@@ -17,7 +17,7 @@
     favorite_moment = models.DateTimeField()
     email = models.EmailField()
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
 __test__ = {'API_TESTS':"""

Modified: 
django/branches/unicode/tests/regressiontests/fixtures_regress/models.py
===================================================================
--- django/branches/unicode/tests/regressiontests/fixtures_regress/models.py    
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/regressiontests/fixtures_regress/models.py    
2007-05-31 04:25:40 UTC (rev 5386)
@@ -4,8 +4,8 @@
     name = models.CharField(maxlength=150)
     latin_name = models.CharField(maxlength=150)
 
-    def __str__(self):
-        return self.common_name    
+    def __unicode__(self):
+        return self.common_name
 
 class Plant(models.Model):
     name = models.CharField(maxlength=150)
@@ -26,4 +26,4 @@
 >>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus')
 >>> animal.save()
 
-"""}
\ No newline at end of file
+"""}

Modified: django/branches/unicode/tests/regressiontests/null_queries/models.py
===================================================================
--- django/branches/unicode/tests/regressiontests/null_queries/models.py        
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/regressiontests/null_queries/models.py        
2007-05-31 04:25:40 UTC (rev 5386)
@@ -3,15 +3,15 @@
 class Poll(models.Model):
     question = models.CharField(maxlength=200)
 
-    def __str__(self):
-        return "Q: %s " % self.question
+    def __unicode__(self):
+        return u"Q: %s " % self.question
 
 class Choice(models.Model):
     poll = models.ForeignKey(Poll)
     choice = models.CharField(maxlength=200)
 
-    def __str__(self):
-        return "Choice: %s in poll %s" % (self.choice, self.poll)
+    def __unicode__(self):
+        return u"Choice: %s in poll %s" % (self.choice, self.poll)
 
 __test__ = {'API_TESTS':"""
 # Regression test for the use of None as a query value. None is interpreted as 

Modified: 
django/branches/unicode/tests/regressiontests/one_to_one_regress/models.py
===================================================================
--- django/branches/unicode/tests/regressiontests/one_to_one_regress/models.py  
2007-05-31 02:22:41 UTC (rev 5385)
+++ django/branches/unicode/tests/regressiontests/one_to_one_regress/models.py  
2007-05-31 04:25:40 UTC (rev 5386)
@@ -4,23 +4,23 @@
     name = models.CharField(maxlength=50)
     address = models.CharField(maxlength=80)
 
-    def __str__(self):
-        return "%s the place" % self.name
+    def __unicode__(self):
+        return u"%s the place" % self.name
 
 class Restaurant(models.Model):
     place = models.OneToOneField(Place)
     serves_hot_dogs = models.BooleanField()
     serves_pizza = models.BooleanField()
 
-    def __str__(self):
-        return "%s the restaurant" % self.place.name
+    def __unicode__(self):
+        return u"%s the restaurant" % self.place.name
 
 class Favorites(models.Model):
     name = models.CharField(maxlength = 50)
     restaurants = models.ManyToManyField(Restaurant)
 
-    def __str__(self):
-        return "Favorites for %s" % self.name
+    def __unicode__(self):
+        return u"Favorites for %s" % self.name
 
 __test__ = {'API_TESTS':"""
 # Regression test for #1064 and #1506: Check that we create models via the m2m


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to