Fix group creation

This commit is contained in:
Gabriel Augendre 2022-11-06 15:57:26 +01:00
parent b929cb6cbd
commit d37b1496bc

View file

@ -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(