diff options
| author | Tim Graham <timograham@gmail.com> | 2016-12-16 17:54:21 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-17 08:59:02 -0500 |
| commit | e1f93e2b1e0da8cdacbb63167bab8732ffbab872 (patch) | |
| tree | fbffebf9298b4f2956ce4664e67b430f28832d11 /docs | |
| parent | bb9c9103e57c7cb09a7d5eb45312ca8808c7a413 (diff) | |
[1.10.x] Refs #25550 -- Removed a deprecated reverse assignment example in docs.
Backport of 8dac9890a5941e7b59ea0ebebed400965941fe09 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/db/queries.txt | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 2f00d0608b..afa1f6be43 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -982,15 +982,16 @@ Due to how inheritance works, you have to set both ``pk`` and ``id`` to None:: django_blog.id = None django_blog.save() # django_blog.pk == 4 -This process does not copy related objects. If you want to copy relations, -you have to write a little bit more code. In our example, ``Entry`` has a many to many -field to ``Author``:: +This process doesn't copy relations that aren't part of the model's database +table. For example, ``Entry`` has a ``ManyToManyField`` to ``Author``. After +duplicating an entry, you must set the many-to-many relations for the new +entry:: entry = Entry.objects.all()[0] # some previous entry old_authors = entry.authors.all() entry.pk = None entry.save() - entry.authors = old_authors # saves new many2many relations + entry.authors.set(old_authors) .. _topics-db-queries-update: |
