How to set user.is_staff to True by default in Django Admin? [closed]
Asked Answered
E

1

11

I need to set the is_staff value to True when creating a user in Admin interface.

How can I do that?

Thanks

Elastin answered 12/2, 2013 at 22:4 Comment(1)
"difficult to tell", ahaPipsissewa
A
14

You can define a custom ModelAdmin and add your custom logic there:

class UserAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        if request.user.is_superuser:
            obj.is_staff = True
            obj.save()

admin.site.register(User, UserAdmin)

You can read more about it here.

Alyosha answered 12/2, 2013 at 22:45 Comment(1)
Glad to help :] don't forget to accept the answer d:Alyosha

© 2022 - 2024 — McMap. All rights reserved.