How to updata all changes on database as one block

I have this code

for i in range(100):
    table2.objects.create(id = i, some_extra_fields)

how to upload all database changes one time in one query

You can use bulk_create to create multiple objects at once:

new_records = []

for i in range(100):
    new_records.append(Table(id=i, ...))


Table.objects.bulk_create(new_records)

Docs in here

Back to Top