다음 코드가 있습니다.
testcase = Table1.objects.filter(ID=id,serialno ='1234', condition='False').exists()
if not testcase:
c = Table1.objects.filter(ID=id,serialno ='1234').select_for_update().update(condition='True')
여기에서는 동일한 DB를 두 번 쿼리합니다. 필터가 존재하고 단일 쿼리로 업데이트 될 수있는 방법이 있습니까?
필터링은 쿼리를 보내지 않습니다. 위의 답변에 동의하지만 코드를 수정하려면 다음이 정확합니다.
testcase = Table1.objects.filter(ID=id,serialno ='1234')
if not testcase.filter(condition='False'):
c = testcase.select_for_update().update(condition='True')
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다