From d37b1496bc7cb9e57d5bf46711803bc4d27daf78 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 6 Nov 2022 15:57:26 +0100 Subject: [PATCH] Fix group creation --- src/party/forms.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/party/forms.py b/src/party/forms.py index 134fd7a..2d6d757 100644 --- a/src/party/forms.py +++ b/src/party/forms.py @@ -5,15 +5,19 @@ from party.models import Party class PartyForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + self.original_instance = kwargs.get("instance") + super().__init__(*args, **kwargs) + class Meta: model = Party fields = ["name", "invited_characters"] def clean_invited_characters(self): invited = self.cleaned_data["invited_characters"] - if not self.instance: + if not self.original_instance: return invited - members = self.instance.characters.all() + members = self.original_instance.characters.all() for character in invited: if character in members: self.add_error(