django select_for_update and select_related on same query?

前端 未结 2 1430
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 18:59

Does anyone know if you can do both the .select_for_update() and .select_related() statements in a single query? Such as:

employee = get_object_or_404(Employ         


        
2条回答
  •  耶瑟儿~
    2021-01-14 19:18

    You can't use select_related with foreign keys that are nullable when you are using select_for_update on the same queryset.

    This will work in all cases:

    Book.objects.select_related().select_for_update().get(name='Doors of perception')
    

提交回复
热议问题