mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Changed all model unit tests to use __str__() instead of __repr__(). Also slightly changed related-object DoesNotExist exception message to use repr instead of str
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3075 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -11,16 +11,16 @@ class Article(models.Model):
|
||||
headline = models.CharField(maxlength=100)
|
||||
pub_date = models.DateField()
|
||||
|
||||
def __repr__(self):
|
||||
def __str__(self):
|
||||
return self.headline
|
||||
|
||||
def was_published_today(self):
|
||||
return self.pub_date == datetime.date.today()
|
||||
|
||||
def get_articles_from_same_day_1(self):
|
||||
def articles_from_same_day_1(self):
|
||||
return Article.objects.filter(pub_date=self.pub_date).exclude(id=self.id)
|
||||
|
||||
def get_articles_from_same_day_2(self):
|
||||
def articles_from_same_day_2(self):
|
||||
"""
|
||||
Verbose version of get_articles_from_same_day_1, which does a custom
|
||||
database query for the sake of demonstration.
|
||||
@@ -47,12 +47,12 @@ API_TESTS = """
|
||||
# Test the custom methods.
|
||||
>>> a.was_published_today()
|
||||
False
|
||||
>>> a.get_articles_from_same_day_1()
|
||||
[Beatles reunite]
|
||||
>>> a.get_articles_from_same_day_2()
|
||||
[Beatles reunite]
|
||||
>>> b.get_articles_from_same_day_1()
|
||||
[Area man programs in Python]
|
||||
>>> b.get_articles_from_same_day_2()
|
||||
[Area man programs in Python]
|
||||
>>> a.articles_from_same_day_1()
|
||||
[<Article: Beatles reunite>]
|
||||
>>> a.articles_from_same_day_2()
|
||||
[<Article: Beatles reunite>]
|
||||
>>> b.articles_from_same_day_1()
|
||||
[<Article: Area man programs in Python>]
|
||||
>>> b.articles_from_same_day_2()
|
||||
[<Article: Area man programs in Python>]
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user