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

后端 未结 5 2052
清酒与你
清酒与你 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:27

    Depends on what you are aiming at. You can use manage.py's loaddata function to load data in a appropriate format (JSON, XML, YAML,...).

    See also this discussion.

提交回复
热议问题