164

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

ivanleoncz
  • 9,070
  • 7
  • 57
  • 49
Neo
  • 5,070
  • 10
  • 46
  • 65

1 Answers1

293

Yes.

obj = get_object_or_404(MyModel.objects.select_related(), whatever=whatever)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Can use multiple where close here obj = get_object_or_404(MyModel.objects.select_related(), whatever=whatever, another=another) – Rajesh M P Oct 06 '20 at 07:47