Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
Django orm mapping raw queries INSERT, UPDATE, DELETE the objects? - bug-code.com Q&A

Django orm mapping raw queries INSERT, UPDATE, DELETE the objects?

0 like 0 dislike
68 views
Hello everyone!
This function takes a list of URLs and creates entries in the batch table:
@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()

The result is a sheet of tuples such as [(1, 'foo.com'), ...].
It would be nice if it returned a list with objects the essence of the Site as if
I made a request like this Site.objects.raw('...')
asked by | 68 views

1 Answer

0 like 0 dislike
it would be bad

or ORM or RAW SQL
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.4k users

24,788 questions
46,220 answers
0 comments
12,374 users