django select_for_update and select_related on same query?

前端 未结 2 1435
爱一瞬间的悲伤
爱一瞬间的悲伤 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:20

    Since Django 2.0, you can use select_for_update together with select_related even on nullable relations - by using new parameter of=...

    Using their Person example from docs, you could do

    Person.objects.select_related('hometown').select_for_update(of=('self',))
    

    which would lock only the Person object

提交回复
热议问题