Question about batch save objects in Django

前端 未结 5 972
一向
一向 2020-12-14 15:47

I haven\'t seen any thing on this topic in Django\'s online documents.

I am trying to save a list of objects to database, but what I can do is loop through the list

5条回答
  •  悲&欢浪女
    2020-12-14 16:02

    From Django 1.4 exists bulk_create(), but, always but.

    You need to be careful, using bulk_create() it wont call instance save() method internally.

    As django docs says

    The model’s save() method will not be called

    So, if you are overriding save method, (as my case was) you can't use bulk_create.

提交回复
热议问题