Changeset 5057
- Timestamp:
- 04/21/07 22:13:00 (1 year ago)
- Files:
-
- django/branches/unicode/django/db/models/base.py (modified) (1 diff)
- django/branches/unicode/tests/modeltests/str/models.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode/django/db/models/base.py
r4893 r5057 87 87 88 88 def __str__(self): 89 if hasattr(self, '__unicode__'): 90 return unicode(self).encode('utf-8') 89 91 return '%s object' % self.__class__.__name__ 90 92 django/branches/unicode/tests/modeltests/str/models.py
r3661 r5057 1 # -*- coding: utf-8 -*- 1 2 """ 2 2. Adding __str__() to models3 2. Adding __str__() or __unicode__() to models 3 4 4 5 Although it's not a strict requirement, each model should have a ``__str__()`` … … 7 8 because objects' representations are used throughout Django's 8 9 automatically-generated admin. 10 11 For international applications, you should write ``__unicode__``() method 12 instead. 9 13 """ 10 14 … … 18 22 return self.headline 19 23 20 __test__ = {'API_TESTS':""" 24 class InternationalArticle(models.Model): 25 headline = models.CharField(maxlength=100) 26 pub_date = models.DateTimeField() 27 28 def __unicode__(self): 29 return self.headline 30 31 __test__ = {'API_TESTS':ur""" 21 32 # Create an Article. 22 33 >>> from datetime import datetime … … 29 40 >>> a 30 41 <Article: Area man programs in Python> 42 43 >>> a1 = InternationalArticle(headline=u'Girl wins â¬12.500 in lottery', pub_date=datetime(2005, 7, 28)) 44 45 # The default str() output will be the UTF-8 encoded output of __unicode__(). 46 >>> str(a1) 47 'Girl wins \xe2\x82\xac12.500 in lottery' 31 48 """}
