From 85657591f5f69f19fec15d94f6e1d3d7a72ebc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Thu, 12 Oct 2017 11:10:30 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20fields=20cleaning=20with=20unreachable=20?= =?UTF-8?q?items=20when=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … object is being created. --- kfet/forms.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kfet/forms.py b/kfet/forms.py index 6ef3aefb..7bafbdd7 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -136,6 +136,8 @@ class UserGroupForm(forms.ModelForm): def clean_groups(self): kfet_groups = self.cleaned_data.get('groups') + if self.instance.pk is None: + return kfet_groups other_groups = self.instance.groups.exclude(name__icontains='K-Fêt') return list(kfet_groups) + list(other_groups) @@ -173,6 +175,8 @@ class GroupForm(forms.ModelForm): # other_groups = self.instance.permissions.difference( # self.fields['permissions'].queryset # ) + if self.instance.pk is None: + return kfet_perms other_perms = self.instance.permissions.exclude( pk__in=[p.pk for p in self.fields['permissions'].queryset], )