How to save user permissions from custom user edit form

20 views
Skip to first unread message

DJ-Tom

unread,
Nov 4, 2017, 11:12:28 AM11/4/17
to Django users
Hi,

I have created the following user form for my custom user model:

class UsersForm(ModelForm):
class Meta:
model = UserAccount
fields = ('is_active', 'is_superuser', 'is_templog', 'is_crewreg', 'is_spaceman','first_name', 'last_name',
'company', 'address1', 'address2', 'address3', 'zipcode', 'city', 'country', 'email', 'favourite_event',
'user_permissions')

def __init__(self, *args, **kwargs):
super(UsersForm, self).__init__(*args, **kwargs)
self.fields['country'].required = False
self.fields['user_permissions'].widget.attrs['class'] = 'input-xxlarge'
self.fields['user_permissions'].widget.attrs['style'] = 'min-height:150px'
self.fields['user_permissions'].help_text = 'Specific permissions for this user. Hold down "Control", or "Command" on a Mac, to select more than one.'



But when I save it via form.save(), any changed permissions are not saved. What do I have to do to change this?

thanks
Thomas
Reply all
Reply to author
Forward
0 new messages