mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #21619 -- Made SingleObjectMixin.get_object catch a more precise exception.
Thanks to Keryn Knight for the report.
This commit is contained in:
parent
a1bc3683ff
commit
cdd6617da6
5 changed files with 29 additions and 4 deletions
|
@ -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']
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue