Ticket #2659: get_object_or_none.patch

File get_object_or_none.patch, 650 bytes (added by Joeboy, 18 years ago)
  • django/shortcuts/__init__.py

     
    1010    return HttpResponse(loader.render_to_string(*args, **kwargs))
    1111load_and_render = render_to_response # For backwards compatibility.
    1212
     13def get_object_or_none(klass, *args, **kwargs):
     14    try:
     15        return klass._default_manager.get(*args, **kwargs)
     16    except klass.DoesNotExist:
     17        return None
     18
    1319def get_object_or_404(klass, *args, **kwargs):
    1420    try:
    1521        return klass._default_manager.get(*args, **kwargs)
Back to Top