A
A
Astrohas2017-01-06 08:12:03
Django
Astrohas, 2017-01-06 08:12:03

How to properly generate ORM objects?

I wanted to generate objects for educational purposes. The action is understandable

for i in range(1000):
    r = Post()
    ....
    r.save()

Alas, it works super slowly, about 100 objects per second. Debug=True and SQLite. Delete is also similar speed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2017-01-06
@Astrohas

Если цель - создавать объекты, то нет ничего быстрее bulk_create. Немного измени твой код, вот так:

posts = []
for i in range(1000):
    r = Post()
    ....
    posts.append(r)

Post.objects.bulk_create(posts)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question