A quick search reveals a gist that contains a number of similar helpers. https://gist.github.com/stkrp/47c536b681082c638849e9a89f77ff05
I think the main problem of going down this path is deciding which are suitable to add and which aren't. I'm not sure that any of them meet the "80% of projects might use this" criteria, and they aren't difficult to implement outside of Django itself. On Tuesday, November 28, 2017 at 5:41:54 PM UTC-5, Piotr Domański wrote: > > Currently we have get_object_or_404 and get_list_or_404 but sometimes we > just want to get first matching record for some criteria. > If criteria aren't unique then get_object_or_404 raises > MultipleObjectsReturned so request ends with internal server error. > > My idea is to add function which returns just first matching element and > ends with 404 if no elements match. > This function will have parameter order_by (optional or required) of type > List['str'] > which determines which element choose first if there are many matching > elements. > > In my opinion addition of this feature is good idea, because it is useful > and safe for Django framework. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6e27e012-4f0a-4dd6-a15a-90d194e48904%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
