R
R
Rrooom2014-09-29 11:53:41
Django
Rrooom, 2014-09-29 11:53:41

How to clone a Django model?

How to clone an object with all related models?
upd. There seems to be no built-in solution. It is necessary to recursively go through all the models and set them to pk=None and save. But it looks sad - a hundred requests in a row. Is it possible to combine a bunch of requests into one pack in django? Well, i.e. the code is executed, but only one combined query will go to the database?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
yttrium, 2014-09-29
@yttrium

Yes. You have to go through all the records.
Learn SQL already. Your "pack" is likely to be completed within a single transaction.

A
Andrey K, 2014-10-01
@mututunus

For this there is bulk_create

I
Ilya, 2014-10-09
@FireGM

Python + psycopg2?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question