Задать вопрос

Тел: +7 965 3737 888

402

Просмотров

1

Ответов

Copy a model instance

<p>Create a copy of a model instance.</p>
<p>Works in model inheritance case where instance.pk = None is
not good enough, since the subclass instance refers to the
parent_link's primary key during save.</p>
<p>M2M relationships are currently not handled, i.e. they are not
copied.</p>
<p>See also Django #4027.</p>

Вопрос полезен? Да0/Нет0
file_2751.py(325.0б)
None

Ответы (1):

Ответasinox:13.05.2012
Ответ полезен? Да0/Нет0

Try this:

from copy import deepcopy old_obj = deepcopy(obj) old_obj.id = None old_obj.save()