Ticket #2756: shortcuts.diff

File shortcuts.diff, 1.2 KB (added by Gary Wilson <gary.wilson@…>, 18 years ago)
  • django/shortcuts/__init__.py

     
    44
    55from django.template import loader
    66from django.http import HttpResponse, Http404
     7from django.db.models.manager import Manager
    78
    89
    910def render_to_response(*args, **kwargs):
     
    1112load_and_render = render_to_response # For backwards compatibility.
    1213
    1314def 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
    1420    try:
    15         return klass._default_manager.get(*args, **kwargs)
     21        return manager.get(*args, **kwargs)
    1622    except klass.DoesNotExist:
    1723        raise Http404
    1824
    1925def 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))
    2131    if not obj_list:
    2232        raise Http404
    2333    return obj_list
Back to Top