Fix initial roles in user form
This commit is contained in:
parent
7c1cd322ed
commit
873e8cc043
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue