2017-02-06 47 views

回答

6

您可以使用F expression從文檔:

記者= Reporters.objects.filter(NAME = '丁丁')

reporter.update(stories_filed = F( 'stories_filed') + 1)

嘗試這種情況:

from django.db.models import F 
Entry.objects.filter(pub_date__year=2010).update(count=F('count') + 1) 
1
for e in Entry.objects.filter(pub_date__year=2010): 
    e.count+= 1 
    e.save() 
+2

謝謝,但這個解決方案很明顯,我寧願避免使用更新的for循環。 – matousc