Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plan_unit duplication #524

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plotsearch/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
@receiver(pre_save, sender=PlotSearchTarget)
def prepare_plan_unit_on_plot_search_target_save(sender, instance, **kwargs):
plan_unit = instance.plan_unit

if plan_unit is None:
return
if plan_unit.is_master:
plan_unit.pk = None
plan_unit.is_master = False
usage_permissions = plan_unit.usage_distributions.all()
plan_unit.save()

for usage_permission in usage_permissions:
usage_permission.pk = None
usage_permission.plan_unit = plan_unit
usage_permission.save()

instance.plan_unit = plan_unit


Expand All @@ -23,6 +31,7 @@ def post_delete_plan_unit_on_plot_search_target_delete(sender, instance, **kwarg
plan_unit = instance.plan_unit
if plan_unit is None:
return
plan_unit.usage_distributions.all().delete()
plan_unit.delete()


Expand Down
Loading