radious radious - 1 year ago 89
Python Question

Adding custom action to UserModel's Admin page

Is there any possibility to create custom action in admin page for django UserModel? I want automatize adding user to group (like adding him to staff, set some extra values, etc.), and of course create actions that take these changes back.

Thanks for your help.

Answer Source

Import User in your unregister it, create new ModelAdmin for it (or subclass the default one) and go wild.

It would look something like this I guess:

from django.contrib.auth.models import User

class UserAdmin(admin.ModelAdmin):
    actions = ['some_action']

    def some_action(self, request, queryset):
        #do something ...
    some_action.short_description = "blabla", UserAdmin)

Reference for actions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download