Skip to content

Commit

Permalink
Tweak some examples.
Browse files Browse the repository at this point in the history
"Area man/woman" is confusing to people not familiar with the
conventions of American journalism (like me).
  • Loading branch information
aaugustin committed Aug 22, 2015
1 parent 0eb8466 commit 491d01b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions docs/topics/db/queries.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -426,13 +426,13 @@ probably use:
:lookup:`exact` :lookup:`exact`
An "exact" match. For example:: An "exact" match. For example::


>>> Entry.objects.get(headline__exact="Man bites dog") >>> Entry.objects.get(headline__exact="Cat bites dog")


Would generate SQL along these lines: Would generate SQL along these lines:


.. code-block:: sql .. code-block:: sql


SELECT ... WHERE headline = 'Man bites dog'; SELECT ... WHERE headline = 'Cat bites dog';


If you don't provide a lookup type -- that is, if your keyword argument If you don't provide a lookup type -- that is, if your keyword argument
doesn't contain a double underscore -- the lookup type is assumed to be doesn't contain a double underscore -- the lookup type is assumed to be
Expand Down
26 changes: 13 additions & 13 deletions tests/basic/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ModelInstanceCreationTests(TestCase):
def test_object_is_not_written_to_database_until_save_was_called(self): def test_object_is_not_written_to_database_until_save_was_called(self):
a = Article( a = Article(
id=None, id=None,
headline='Area man programs in Python', headline='Parrot programs in Python',
pub_date=datetime(2005, 7, 28), pub_date=datetime(2005, 7, 28),
) )
self.assertIsNone(a.id) self.assertIsNone(a.id)
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_saving_an_object_again_does_not_create_a_new_object(self):


def test_querysets_checking_for_membership(self): def test_querysets_checking_for_membership(self):
headlines = [ headlines = [
'Area man programs in Python', 'Second article', 'Third article'] 'Parrot programs in Python', 'Second article', 'Third article']
some_pub_date = datetime(2014, 5, 16, 12, 1) some_pub_date = datetime(2014, 5, 16, 12, 1)
for headline in headlines: for headline in headlines:
Article(headline=headline, pub_date=some_pub_date).save() Article(headline=headline, pub_date=some_pub_date).save()
Expand Down Expand Up @@ -437,25 +437,25 @@ def setUp(self):
# Create an Article. # Create an Article.
self.a = Article( self.a = Article(
id=None, id=None,
headline='Area woman programs in Python', headline='Swallow programs in Python',
pub_date=datetime(2005, 7, 28), pub_date=datetime(2005, 7, 28),
) )
# Save it into the database. You have to call save() explicitly. # Save it into the database. You have to call save() explicitly.
self.a.save() self.a.save()


def test_all_lookup(self): def test_all_lookup(self):
# Change values by changing the attributes, then calling save(). # Change values by changing the attributes, then calling save().
self.a.headline = 'Area man programs in Python' self.a.headline = 'Parrot programs in Python'
self.a.save() self.a.save()


# Article.objects.all() returns all the articles in the database. # Article.objects.all() returns all the articles in the database.
self.assertQuerysetEqual(Article.objects.all(), self.assertQuerysetEqual(Article.objects.all(),
['<Article: Area man programs in Python>']) ['<Article: Parrot programs in Python>'])


def test_rich_lookup(self): def test_rich_lookup(self):
# Django provides a rich database lookup API. # Django provides a rich database lookup API.
self.assertEqual(Article.objects.get(id__exact=self.a.id), self.a) self.assertEqual(Article.objects.get(id__exact=self.a.id), self.a)
self.assertEqual(Article.objects.get(headline__startswith='Area woman'), self.a) self.assertEqual(Article.objects.get(headline__startswith='Swallow'), self.a)
self.assertEqual(Article.objects.get(pub_date__year=2005), self.a) self.assertEqual(Article.objects.get(pub_date__year=2005), self.a)
self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7), self.a) self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7), self.a)
self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28), self.a) self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28), self.a)
Expand All @@ -464,24 +464,24 @@ def test_rich_lookup(self):
def test_equal_lookup(self): def test_equal_lookup(self):
# The "__exact" lookup type can be omitted, as a shortcut. # The "__exact" lookup type can be omitted, as a shortcut.
self.assertEqual(Article.objects.get(id=self.a.id), self.a) self.assertEqual(Article.objects.get(id=self.a.id), self.a)
self.assertEqual(Article.objects.get(headline='Area woman programs in Python'), self.a) self.assertEqual(Article.objects.get(headline='Swallow programs in Python'), self.a)


self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(pub_date__year=2005), Article.objects.filter(pub_date__year=2005),
['<Article: Area woman programs in Python>'], ['<Article: Swallow programs in Python>'],
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(pub_date__year=2004), Article.objects.filter(pub_date__year=2004),
[], [],
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(pub_date__year=2005, pub_date__month=7), Article.objects.filter(pub_date__year=2005, pub_date__month=7),
['<Article: Area woman programs in Python>'], ['<Article: Swallow programs in Python>'],
) )


self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(pub_date__week_day=5), Article.objects.filter(pub_date__week_day=5),
['<Article: Area woman programs in Python>'], ['<Article: Swallow programs in Python>'],
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.filter(pub_date__week_day=6), Article.objects.filter(pub_date__week_day=6),
Expand Down Expand Up @@ -522,7 +522,7 @@ def test_lookup_by_primary_key(self):


# pk can be used as a shortcut for the primary key name in any query. # pk can be used as a shortcut for the primary key name in any query.
self.assertQuerysetEqual(Article.objects.filter(pk__in=[self.a.id]), self.assertQuerysetEqual(Article.objects.filter(pk__in=[self.a.id]),
["<Article: Area woman programs in Python>"]) ["<Article: Swallow programs in Python>"])


# Model instances of the same type and same ID are considered equal. # Model instances of the same type and same ID are considered equal.
a = Article.objects.get(pk=self.a.id) a = Article.objects.get(pk=self.a.id)
Expand All @@ -533,7 +533,7 @@ def test_too_many(self):
# Create a very similar object # Create a very similar object
a = Article( a = Article(
id=None, id=None,
headline='Area man programs in Python', headline='Swallow bites Python',
pub_date=datetime(2005, 7, 28), pub_date=datetime(2005, 7, 28),
) )
a.save() a.save()
Expand All @@ -547,7 +547,7 @@ def test_too_many(self):
MultipleObjectsReturned, MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!", "get\(\) returned more than one Article -- it returned 2!",
Article.objects.get, Article.objects.get,
headline__startswith='Area', headline__startswith='Swallow',
) )
six.assertRaisesRegex( six.assertRaisesRegex(
self, self,
Expand Down
6 changes: 3 additions & 3 deletions tests/custom_methods/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class MethodsTests(TestCase): class MethodsTests(TestCase):
def test_custom_methods(self): def test_custom_methods(self):
a = Article.objects.create( a = Article.objects.create(
headline="Area man programs in Python", pub_date=date(2005, 7, 27) headline="Parrot programs in Python", pub_date=date(2005, 7, 27)
) )
b = Article.objects.create( b = Article.objects.create(
headline="Beatles reunite", pub_date=date(2005, 7, 27) headline="Beatles reunite", pub_date=date(2005, 7, 27)
Expand All @@ -32,13 +32,13 @@ def test_custom_methods(self):


self.assertQuerysetEqual( self.assertQuerysetEqual(
b.articles_from_same_day_1(), [ b.articles_from_same_day_1(), [
"Area man programs in Python", "Parrot programs in Python",
], ],
lambda a: a.headline, lambda a: a.headline,
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
b.articles_from_same_day_2(), [ b.articles_from_same_day_2(), [
"Area man programs in Python", "Parrot programs in Python",
], ],
lambda a: a.headline lambda a: a.headline
) )
16 changes: 8 additions & 8 deletions tests/m2m_multiple/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def test_multiple(self):
] ]


a1 = Article.objects.create( a1 = Article.objects.create(
headline="Area man steals", pub_date=datetime(2005, 11, 27) headline="Parrot steals", pub_date=datetime(2005, 11, 27)
) )
a1.primary_categories.add(c2, c3) a1.primary_categories.add(c2, c3)
a1.secondary_categories.add(c4) a1.secondary_categories.add(c4)


a2 = Article.objects.create( a2 = Article.objects.create(
headline="Area man runs", pub_date=datetime(2005, 11, 28) headline="Parrot runs", pub_date=datetime(2005, 11, 28)
) )
a2.primary_categories.add(c1, c2) a2.primary_categories.add(c1, c2)
a2.secondary_categories.add(c4) a2.secondary_categories.add(c4)
Expand All @@ -48,7 +48,7 @@ def test_multiple(self):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
c1.primary_article_set.all(), [ c1.primary_article_set.all(), [
"Area man runs", "Parrot runs",
], ],
lambda a: a.headline lambda a: a.headline
) )
Expand All @@ -57,8 +57,8 @@ def test_multiple(self):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
c2.primary_article_set.all(), [ c2.primary_article_set.all(), [
"Area man steals", "Parrot steals",
"Area man runs", "Parrot runs",
], ],
lambda a: a.headline lambda a: a.headline
) )
Expand All @@ -67,7 +67,7 @@ def test_multiple(self):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
c3.primary_article_set.all(), [ c3.primary_article_set.all(), [
"Area man steals", "Parrot steals",
], ],
lambda a: a.headline lambda a: a.headline
) )
Expand All @@ -79,8 +79,8 @@ def test_multiple(self):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
c4.secondary_article_set.all(), [ c4.secondary_article_set.all(), [
"Area man steals", "Parrot steals",
"Area man runs", "Parrot runs",
], ],
lambda a: a.headline lambda a: a.headline
) )
6 changes: 3 additions & 3 deletions tests/str/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class SimpleTests(TestCase):
@skipIf(six.PY3, "tests a __str__ method returning unicode under Python 2") @skipIf(six.PY3, "tests a __str__ method returning unicode under Python 2")
def test_basic(self): def test_basic(self):
a = Article.objects.create( a = Article.objects.create(
headline=b'Area man programs in Python', headline=b'Parrot programs in Python',
pub_date=datetime.datetime(2005, 7, 28) pub_date=datetime.datetime(2005, 7, 28)
) )
self.assertEqual(str(a), str('Area man programs in Python')) self.assertEqual(str(a), str('Parrot programs in Python'))
self.assertEqual(repr(a), str('<Article: Area man programs in Python>')) self.assertEqual(repr(a), str('<Article: Parrot programs in Python>'))


def test_international(self): def test_international(self):
a = InternationalArticle.objects.create( a = InternationalArticle.objects.create(
Expand Down

0 comments on commit 491d01b

Please sign in to comment.