From db58fb34eb5fb4c47f3136f7f37573a481cbcd81 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 18 Feb 2023 21:42:56 +0000 Subject: [PATCH] Ensure an account only has one strategy with active management --- core/forms.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/forms.py b/core/forms.py index 4f54b2c..2592d53 100644 --- a/core/forms.py +++ b/core/forms.py @@ -217,6 +217,21 @@ class StrategyForm(RestrictedFormMixin, ModelForm): ] ) if cleaned_data.get("active_management_enabled"): + # Ensure that no other strategy with this account has active management enabled + if ( + Strategy.objects.filter( + account=cleaned_data.get("account"), + active_management_enabled=True, + enabled=True, + ) + .exclude(id=self.instance.id) + .exists() + ): + self.add_error( + "active_management_enabled", + "You cannot have more than one strategy with active management enabled for the same account.", + ) + return if not cleaned_data.get("active_management_policy"): self.add_error( "active_management_policy",