IF 조건을 사용할 때 django의 단일 쿼리에서 DB 업데이트를 수행하는 방법은 무엇입니까?

vp_5614

다음 코드가 있습니다.

 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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관