Loading django/db/models/query.py +8 −4 Original line number Diff line number Diff line Loading @@ -363,10 +363,14 @@ class QuerySet(object): if num == 1: return clone._result_cache[0] if not num: raise self.model.DoesNotExist("%s matching query does not exist." % self.model._meta.object_name) raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, num, kwargs)) raise self.model.DoesNotExist( "%s matching query does not exist. " "Lookup parameters were %s" % (self.model._meta.object_name, kwargs)) raise self.model.MultipleObjectsReturned( "get() returned more than one %s -- it returned %s! " "Lookup parameters were %s" % (self.model._meta.object_name, num, kwargs)) def create(self, **kwargs): """ Loading docs/intro/overview.txt +1 −1 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ access your data. The API is created on the fly, no code generation necessary:: >>> Reporter.objects.get(id=2) Traceback (most recent call last): ... DoesNotExist: Reporter matching query does not exist. DoesNotExist: Reporter matching query does not exist. Lookup parameters were {'id': 2} # Create an article. >>> from datetime import datetime Loading docs/intro/tutorial01.txt +1 −1 Original line number Diff line number Diff line Loading @@ -664,7 +664,7 @@ Save these changes and start a new Python interactive shell by running >>> Poll.objects.get(id=2) Traceback (most recent call last): ... DoesNotExist: Poll matching query does not exist. DoesNotExist: Poll matching query does not exist. Lookup parameters were {'id': 2} # Lookup by a primary key is the most common case, so Django provides a # shortcut for primary-key exact lookups. Loading tests/modeltests/basic/tests.py +14 −4 Original line number Diff line number Diff line Loading @@ -83,14 +83,23 @@ class ModelTest(TestCase): # parameters don't match any object. self.assertRaisesRegexp( ObjectDoesNotExist, "Article matching query does not exist.", "Article matching query does not exist. Lookup parameters were " "{'id__exact': 2000}", Article.objects.get, id__exact=2000, ) # To avoid dict-ordering related errors check only one lookup # in single assert. self.assertRaisesRegexp( ObjectDoesNotExist, ".*'pub_date__year': 2005.*", Article.objects.get, pub_date__year=2005, pub_date__month=8, ) self.assertRaisesRegexp( ObjectDoesNotExist, "Article matching query does not exist.", ".*'pub_date__month': 8.*", Article.objects.get, pub_date__year=2005, pub_date__month=8, Loading @@ -98,7 +107,8 @@ class ModelTest(TestCase): self.assertRaisesRegexp( ObjectDoesNotExist, "Article matching query does not exist.", "Article matching query does not exist. Lookup parameters were " "{'pub_date__week_day': 6}", Article.objects.get, pub_date__week_day=6, ) Loading Loading
django/db/models/query.py +8 −4 Original line number Diff line number Diff line Loading @@ -363,10 +363,14 @@ class QuerySet(object): if num == 1: return clone._result_cache[0] if not num: raise self.model.DoesNotExist("%s matching query does not exist." % self.model._meta.object_name) raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, num, kwargs)) raise self.model.DoesNotExist( "%s matching query does not exist. " "Lookup parameters were %s" % (self.model._meta.object_name, kwargs)) raise self.model.MultipleObjectsReturned( "get() returned more than one %s -- it returned %s! " "Lookup parameters were %s" % (self.model._meta.object_name, num, kwargs)) def create(self, **kwargs): """ Loading
docs/intro/overview.txt +1 −1 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ access your data. The API is created on the fly, no code generation necessary:: >>> Reporter.objects.get(id=2) Traceback (most recent call last): ... DoesNotExist: Reporter matching query does not exist. DoesNotExist: Reporter matching query does not exist. Lookup parameters were {'id': 2} # Create an article. >>> from datetime import datetime Loading
docs/intro/tutorial01.txt +1 −1 Original line number Diff line number Diff line Loading @@ -664,7 +664,7 @@ Save these changes and start a new Python interactive shell by running >>> Poll.objects.get(id=2) Traceback (most recent call last): ... DoesNotExist: Poll matching query does not exist. DoesNotExist: Poll matching query does not exist. Lookup parameters were {'id': 2} # Lookup by a primary key is the most common case, so Django provides a # shortcut for primary-key exact lookups. Loading
tests/modeltests/basic/tests.py +14 −4 Original line number Diff line number Diff line Loading @@ -83,14 +83,23 @@ class ModelTest(TestCase): # parameters don't match any object. self.assertRaisesRegexp( ObjectDoesNotExist, "Article matching query does not exist.", "Article matching query does not exist. Lookup parameters were " "{'id__exact': 2000}", Article.objects.get, id__exact=2000, ) # To avoid dict-ordering related errors check only one lookup # in single assert. self.assertRaisesRegexp( ObjectDoesNotExist, ".*'pub_date__year': 2005.*", Article.objects.get, pub_date__year=2005, pub_date__month=8, ) self.assertRaisesRegexp( ObjectDoesNotExist, "Article matching query does not exist.", ".*'pub_date__month': 8.*", Article.objects.get, pub_date__year=2005, pub_date__month=8, Loading @@ -98,7 +107,8 @@ class ModelTest(TestCase): self.assertRaisesRegexp( ObjectDoesNotExist, "Article matching query does not exist.", "Article matching query does not exist. Lookup parameters were " "{'pub_date__week_day': 6}", Article.objects.get, pub_date__week_day=6, ) Loading