Updated Django Shortucts

July 25, 2007

My code was checked in as of Revision 5796, giving get_object_or_404 and get_list_or_404 the ability to accept QuerySets. Previously, these shortcuts functions only supported Models or Managers:

get_object_or_404(Poll, pk=1)
get_object_or_404(Poll.my_objects, pk=1)

Now with QuerySets:

get_object_or_404(Poll.objects.live(), pk=1)

Documentation and tests are already up-to-date, as they were required for my patch. This change reduces a lot of redundant code because, as you’ve seen in a previous post, I use custom Managers in a way different than the ‘standard’ documented way.

Thanks to Gary Wilson for checking in the code.


Comments

You, sir, are awesome. Now I can go clean out my try/except cruft, woo! Thanks for adding this.

Posted by Nathan Ostgard

Add your comment

No HTML; Only URLs and line breaks are converted.