Opened 5 years ago

Closed 5 years ago

#23500 closed New feature (worksforme)

Allow get_object_or_404 to accept select_related and prefetch_related

Reported by: Abhin Chhabra Owned by: nobody
Component: Utilities Version: master
Severity: Normal Keywords: get_object_or_404 select_related prefetch_related
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


get_object_or_404 is a nice helper, but it doesn't support select_related and prefetch_related. At my company, we've had to implement that ourselves, but it would be great if Django had support for those to begin with.

I will totally be willing to create the patch myself, but I want to figure out whether there is support for this improvement. Please let me know if you approve of this change.

Change History (1)

comment:1 Changed 5 years ago by Carl Meyer

Resolution: worksforme
Status: newclosed

The first argument to get_object_or_404 can be a model or manager or query set; therefore it supports all query set methods.

get_object_or_404(MyModel.objects.select_related(), pk=1)
Note: See TracTickets for help on using tickets.
Back to Top