Efficient way to bulk insert with get_or_create() in Django (SQL, Python, Django)

后端 未结 5 2069
清酒与你
清酒与你 2020-12-14 02:13

Is there a more efficient way for doing this?

for item in item_list:
    e, new = Entry.objects.get_or_create(
        field1 = item.field1,
        field2 =         


        
5条回答
  •  伪装坚强ぢ
    2020-12-14 02:18

    Since 1.4 you can do bulk_create

    See the docs

    *Do pay attention to the caveats though (most important one being that the model’s save() method will not be called, and thus the pre_save and post_save signals will not be sent.) *

提交回复
热议问题