From 873e8cc043e7b0a7e065b280aa83e9d6e35cf58e Mon Sep 17 00:00:00 2001 From: shagi Date: Wed, 12 May 2021 16:10:27 +0200 Subject: [PATCH] Fix initial roles in user form --- gas/forms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gas/forms.py b/gas/forms.py index 3fc654a..66f6fce 100644 --- a/gas/forms.py +++ b/gas/forms.py @@ -25,6 +25,7 @@ class UserForm(forms.ModelForm): label=_('roles'), required=False, ) + class Meta: model = User fields = ( @@ -33,8 +34,8 @@ class UserForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - if 'roles' not in self.initial and self.instance.pk is not None: - self.initial['roles'] = self.instance.user_roles.values_list('role', flat=True) + if self.instance.pk is not None: + self.initial['roles'] = list(self.instance.user_roles.values_list('role', flat=True)) def save(self, commit=True): obj = super().save(commit=False)