Ticket #3511: 3511.2.diff
File 3511.2.diff, 4.2 KB (added by , 17 years ago) |
---|
-
django/db/models/base.py
1 1 import django.db.models.manipulators 2 2 import django.db.models.manager 3 3 from django.core import validators 4 from django.core.exceptions import ObjectDoesNotExist 4 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned 5 5 from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist 6 6 from django.db.models.fields.related import OneToOneRel, ManyToOneRel 7 7 from django.db.models.query import delete_objects … … 35 35 new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')}) 36 36 new_class.add_to_class('_meta', Options(attrs.pop('Meta', None))) 37 37 new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) 38 new_class.add_to_class('MultipleObjectsReturned', 39 types.ClassType('MultipleObjectsReturned', (MultipleObjectsReturned, ), {})) 38 40 39 41 # Build complete list of parents 40 42 for base in bases: -
django/db/models/query.py
261 261 obj_list = list(clone) 262 262 if len(obj_list) < 1: 263 263 raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name 264 assert len(obj_list) == 1, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs) 264 elif len(obj_list) > 1: 265 raise self.model.MultipleObjectsReturned, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs) 265 266 return obj_list[0] 266 267 267 268 def create(self, **kwargs): -
django/core/exceptions.py
4 4 "The requested object does not exist" 5 5 silent_variable_failure = True 6 6 7 class MultipleObjectsReturned(Exception): 8 "The query returned multiple objects when only one was expected." 9 pass 10 7 11 class SuspiciousOperation(Exception): 8 12 "The user did something suspicious" 9 13 pass -
django/shortcuts/__init__.py
38 38 klass may be a Model, Manager, or QuerySet object. All other passed 39 39 arguments and keyword arguments are used in the get() query. 40 40 41 Note: Like with get(), an AssertionErrorwill be raised if more than one41 Note: Like with get(), an MultipleObjectsReturned will be raised if more than one 42 42 object is found. 43 43 """ 44 44 queryset = _get_queryset(klass) -
tests/modeltests/get_object_or_404/models.py
78 78 >>> get_object_or_404(Author.objects.all()) 79 79 Traceback (most recent call last): 80 80 ... 81 AssertionError: get() returned more than one Author -- it returned ...! Lookup parameters were {}81 MultipleObjectsReturned: get() returned more than one Author -- it returned ...! Lookup parameters were {} 82 82 83 83 # Using an EmptyQuerySet raises a Http404 error. 84 84 >>> get_object_or_404(Article.objects.none(), title__contains="Run") -
docs/shortcuts.txt
98 98 except MyModel.DoesNotExist: 99 99 raise Http404 100 100 101 Note: As with ``get()``, an `` AssertionError`` will be raised if more than102 one object is found.101 Note: As with ``get()``, an ``MultipleObjectsReturned`` exception will be 102 raised if more than one object is found. 103 103 104 104 .. _get(): ../db-api/#get-kwargs 105 105