Answer the question
In order to leave comments, you need to log in
Django orm mapping raw INSERT, UPDATE, DELETE queries to objects?
Hello everyone!
This function takes a list of urls, and creates entries in the table in batch:
@transaction.atomic
def site_bulk_create(urls):
sql = 'INSERT INTO public.app_core_site (url) VALUES '
values = ["('{}')".format(url) for url in urls]
sql += ', '.join(values)
sql += ' RETURNING *'
with connection.cursor() as cursor:
cursor.execute(sql)
return cursor.fetchall()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question