2👍
✅
Use bulk create to to save new objects in one query:
obj_list = []
for code in code_list:
obj_list.append(PPTLcode(code = code, pconf = pconf_obj))
PPTLcode.objects.bulk_create(obj_list)
Or a one line solution:
PPTLcode.objects.bulk_create([PPTLcode(code=code, pconf=pconf_obj) for code in code_list])
Note: bulk_create
is avaliable in django >= 1.4
Source:stackexchange.com