1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #12152. DoesNotExist and MultipleObjectsReturned now subclass their parent model's exceptions. Thanks, mattmcc and Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12567 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans
2010-02-24 14:32:11 +00:00
parent de1ff3e51d
commit 1089bda546
3 changed files with 73 additions and 8 deletions

View File

@@ -38,6 +38,9 @@ class Student(CommonInfo):
class Meta:
pass
class StudentWorker(Student, Worker):
pass
#
# Abstract base classes with related models
#
@@ -176,6 +179,32 @@ Traceback (most recent call last):
...
AttributeError: type object 'CommonInfo' has no attribute 'objects'
# A StudentWorker which does not exist is both a Student and Worker which does not exist.
>>> try:
... StudentWorker.objects.get(id=1)
... except Student.DoesNotExist:
... pass
>>> try:
... StudentWorker.objects.get(id=1)
... except Worker.DoesNotExist:
... pass
# MultipleObjectsReturned is also inherited.
>>> sw1 = StudentWorker()
>>> sw1.name = 'Wilma'
>>> sw1.age = 35
>>> sw1.save()
>>> sw2 = StudentWorker()
>>> sw2.name = 'Betty'
>>> sw2.age = 34
>>> sw2.save()
>>> try:
... StudentWorker.objects.get(id__lt=10)
... except Student.MultipleObjectsReturned:
... pass
... except Worker.MultipleObjectsReturned:
... pass
# Create a Post
>>> post = Post(title='Lorem Ipsum')
>>> post.save()
@@ -267,6 +296,18 @@ Traceback (most recent call last):
...
DoesNotExist: ItalianRestaurant matching query does not exist.
# An ItalianRestaurant which does not exist is also a Place which does not exist.
>>> try:
... ItalianRestaurant.objects.get(name='The Noodle Void')
... except Place.DoesNotExist:
... pass
# MultipleObjectsReturned is also inherited.
>>> try:
... Restaurant.objects.get(id__lt=10)
... except Place.MultipleObjectsReturned:
... pass
# Related objects work just as they normally do.
>>> s1 = Supplier(name="Joe's Chickens", address='123 Sesame St')