1
我有一個代碼,像這樣Django的交易
def many_objects_saving(list_of_objects):
for some_object in list_of_objects:
# do smth with an object
some_object.save()
據我所知,Django是會打的數據庫,每次它達到保存()的代碼。因此,這裏有兩個問題:
- 如果我會在另外一個使用此功能,並使其包裹着
transaction.commit_on_success
或transaction.commit_manually
裝飾,將Django的做,在短短一個事務中的所有保存和訪問數據庫以下(內一個函數)?
例如:
def resave_objects(model, condition):
list_of_objects = model.objects.filter(**condition)
many_objects_save(list_of_objects)
@transaction.commit_on_success
def many_objects_save(list_of_objects):
for some_object in list_of_objects:
# do smth with an object
some_object.save()
2.如果是這樣,這將是對大型查詢集更好? 謝謝你們!
謝謝!!!))) –