Kaydet (Commit) 8dac9890 authored tarafından Tim Graham's avatar Tim Graham

Refs #25550 -- Removed a deprecated reverse assignment example in docs.

üst af5983e4
...@@ -974,15 +974,16 @@ Due to how inheritance works, you have to set both ``pk`` and ``id`` to None:: ...@@ -974,15 +974,16 @@ Due to how inheritance works, you have to set both ``pk`` and ``id`` to None::
django_blog.id = None django_blog.id = None
django_blog.save() # django_blog.pk == 4 django_blog.save() # django_blog.pk == 4
This process does not copy related objects. If you want to copy relations, This process doesn't copy relations that aren't part of the model's database
you have to write a little bit more code. In our example, ``Entry`` has a many to many table. For example, ``Entry`` has a ``ManyToManyField`` to ``Author``. After
field to ``Author``:: duplicating an entry, you must set the many-to-many relations for the new
entry::
entry = Entry.objects.all()[0] # some previous entry entry = Entry.objects.all()[0] # some previous entry
old_authors = entry.authors.all() old_authors = entry.authors.all()
entry.pk = None entry.pk = None
entry.save() entry.save()
entry.authors = old_authors # saves new many2many relations entry.authors.set(old_authors)
.. _topics-db-queries-update: .. _topics-db-queries-update:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment