django : using select_related and get_object_or_404 together

試著忘記壹切 提交于 2020-01-28 13:16:10

问题


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


回答1:


Yes.

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


来源:https://stackoverflow.com/questions/6624530/django-using-select-related-and-get-object-or-404-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!