How to use 'select_related' with get_object_or_404?
Asked Answered
C

1

169

Is there any way of using get_object_or_404 and select_related together or any other way to achieve the result of using these two together(except from putting it in try/except)??

Cunningham answered 8/7, 2011 at 12:38 Comment(0)
P
300

Yes.

obj = get_object_or_404(MyModel.objects.select_related(), whatever=whatever)
Prehensible answered 8/7, 2011 at 12:49 Comment(1)
Can use multiple where close here obj = get_object_or_404(MyModel.objects.select_related(), whatever=whatever, another=another)Fuze

© 2022 - 2024 — McMap. All rights reserved.