1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Documented how to copy a OneToOneField.

Thanks Anton Gilgur for the report and review.
This commit is contained in:
Tim Graham 2016-12-16 18:34:41 -05:00
parent 8dac9890a5
commit 2f44fa7f06

View File

@ -985,6 +985,15 @@ entry::
entry.save() entry.save()
entry.authors.set(old_authors) entry.authors.set(old_authors)
For a ``OneToOneField``, you must duplicate the related object and assign it
to the new object's field to avoid violating the one-to-one unique constraint.
For example, assuming ``entry`` is already duplicated as above::
detail = EntryDetail.objects.all()[0]
detail.pk = None
detail.entry = entry
detail.save()
.. _topics-db-queries-update: .. _topics-db-queries-update:
Updating multiple objects at once Updating multiple objects at once