django : using select_related and get_object_or_404 together

DjangoDjango Models

Django Problem Overview


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)??

Django Solutions


Solution 1 - Django

Yes.

obj = get_object_or_404(MyModel.objects.select_related(), whatever=whatever)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNeoView Question on Stackoverflow
Solution 1 - DjangoDaniel RosemanView Answer on Stackoverflow