Skip to content

Commit

Permalink
Bugfix: Chart specific options require to be copied on publish
Browse files Browse the repository at this point in the history
  • Loading branch information
carderm committed Mar 26, 2023
1 parent 3c10286 commit 730d84e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions djangocms_charts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ class ChartModel(CMSPlugin, DatasetBase):
chart_options_group = models.ForeignKey(ChartOptionsGroupModel, on_delete=models.CASCADE,
related_name="chart_options", blank=True, null=True)

def copy_relations(self, old_instance):
# 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.options.all().delete()

for option in old_instance.options.all():
# standard Django way of copying a saved model instance
option.pk = None
option.options_group = self
option.save()

def get_chart_width(self):
if self.chart_width.isnumeric():
return f'{self.chart_width}px'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='djangocms_charts',
version='3.0.3',
version='3.0.4',
packages=find_packages(),
include_package_data=True,
license='MIT License',
Expand Down

0 comments on commit 730d84e

Please sign in to comment.