|Reported by:||Chuck Harmston||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
First time contributor (not just to Django, but to any open source project), so go easy on me.
Several times I've found myself wanting for a get_list_or_none() shortcut method. get_list_or_404 is nice, but there are some instances (search results, for example) where returning an empty QuerySet makes much more sense. Attached is a patch adding functional get_list_or_404 and get_object_or_404 methods to django.shortcuts. I am aware that in #2659 Adrian rejected get_object_or_404 as scope creep, but since that time objects.none() has been introduced, which would render these methods much more useful. Feel free to set it as wontfix if you still think it's scope creep, but these are certainly useful methods for me, and I'm sure they would be for others as well.
I have not run unit tests on this; it seems to me that it would make more sense to get community buy-in on the necessity for these methods first.
Feedback welcome. Thanks all!
Change History (12)
comment:1 Changed 7 years ago by
|Patch needs improvement:||unset|
comment:3 Changed 7 years ago by
|Summary:||get_object/list_or_404 methods → get_object/list_or_none methods|