Ticket #2756: shortcuts.diff
File shortcuts.diff, 1.2 KB (added by , 18 years ago) |
---|
-
django/shortcuts/__init__.py
4 4 5 5 from django.template import loader 6 6 from django.http import HttpResponse, Http404 7 from django.db.models.manager import Manager 7 8 8 9 9 10 def render_to_response(*args, **kwargs): … … 11 12 load_and_render = render_to_response # For backwards compatibility. 12 13 13 14 def get_object_or_404(klass, *args, **kwargs): 15 if isinstance(klass, Manager): 16 manager = klass 17 klass = manager.model 18 else: 19 manager = klass._default_manager 14 20 try: 15 return klass._default_manager.get(*args, **kwargs)21 return manager.get(*args, **kwargs) 16 22 except klass.DoesNotExist: 17 23 raise Http404 18 24 19 25 def get_list_or_404(klass, *args, **kwargs): 20 obj_list = list(klass._default_manager.filter(*args, **kwargs)) 26 if isinstance(klass, Manager): 27 manager = klass 28 else: 29 manager = klass._default_manager 30 obj_list = list(manager.filter(*args, **kwargs)) 21 31 if not obj_list: 22 32 raise Http404 23 33 return obj_list