Skip to content

Commit

Permalink
Improve documentation for copy_relations method (django-cms#5750)
Browse files Browse the repository at this point in the history
Before coping related objects from old instance current one need
to be deleted or at public version of the page can appear duplicates
  • Loading branch information
vstoykov authored and czpython committed Nov 10, 2016
1 parent e077b5e commit 9c79fae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/how_to/custom_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ new plugin::
title = models.CharField(max_length=50)

def copy_relations(self, oldinstance):
# Before copying related objects from the old instance, the ones
# on the current one need to be deleted. Otherwise, duplicates may
# appear on the public version of the page
self.associated_item.all().delete()

for associated_item in oldinstance.associated_item.all():
# instance.pk = None; instance.pk.save() is the slightly odd but
# standard Django way of copying a saved model instance
Expand Down

0 comments on commit 9c79fae

Please sign in to comment.