I need to set the is_staff value to True when creating a user in Admin interface.
在Admin界面中创建用户时,我需要将is_staff值设置为True。
How can I do that?
我怎样才能做到这一点?
Thanks
谢谢
1 个解决方案
#1
8
You can define a custom ModelAdmin and add your custom logic there:
您可以定义自定义ModelAdmin并在其中添加自定义逻辑:
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.
你可以在这里读更多关于它的内容。
#1
8
You can define a custom ModelAdmin and add your custom logic there:
您可以定义自定义ModelAdmin并在其中添加自定义逻辑:
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.
你可以在这里读更多关于它的内容。