Bulk create model objects in django

后端 未结 8 2027
执笔经年
执笔经年 2020-12-13 05:17

I have a lot of objects to save in database, and so I want to create Model instances with that.

With django, I can create all the models instances, with MyMode

8条回答
  •  猫巷女王i
    2020-12-13 05:59

    The easiest way is to use the create Manager method, which creates and saves the object in a single step.

    for item in items:
        MyModel.objects.create(name=item.name)
    

提交回复
热议问题