Fixed #21619 -- Made SingleObjectMixin.get_object catch a more precise exception.

Thanks to Keryn Knight for the report.
This commit is contained in:
Peter Harley 2013-12-14 23:15:35 +00:00 committed by Baptiste Mispelon
parent a1bc3683ff
commit cdd6617da6
5 changed files with 29 additions and 4 deletions

View file

@ -1,5 +1,7 @@
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import QuerySet
from django.db.models.manager import BaseManager
from django.utils.encoding import python_2_unicode_compatible
@ -31,6 +33,13 @@ class Author(models.Model):
return self.name
class DoesNotExistQuerySet(QuerySet):
def get(self, *args, **kwargs):
raise Author.DoesNotExist
DoesNotExistBookManager = BaseManager.from_queryset(DoesNotExistQuerySet)
@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=300)
@ -39,6 +48,9 @@ class Book(models.Model):
authors = models.ManyToManyField(Author)
pubdate = models.DateField()
objects = models.Manager()
does_not_exist = DoesNotExistBookManager()
class Meta:
ordering = ['-pubdate']