A
A
adrenalinruslan2019-09-17 21:13:39
Django
adrenalinruslan, 2019-09-17 21:13:39

Prepare queries to be added in a loop?

I would like to know if it is possible in django to prepare requests for adding in a cycle, and after the cycle, send this request to add records to the database.
At the moment, I have the following added to the database:

for value in _history:
  History.objects.create(
    description = value['description']
  )

But this adds a long time)
Before I switched to django, I did this and added records much faster, or it seems to me (but this is unlikely):
for value in _history:
  with connection.cursor() as cursor:
    cursor.execute("INSERT INTO `history`(`description`) VALUES (%(description)s)", {
      "description": value["description"]
    })

connection.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2019-09-17
@adrenalinruslan

https://docs.djangoproject.com/en/2.2/ref/models/q...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question