user2895021
user2895021

Reputation: 1

Change 'SuperUser' label and description in Django admin

I'd like to change the label and description of the is_superuser field in the Django admin.

I've seen this question asked before but this is not quite what I need.

What I want is change the 'Superuser status' string to something else and also change this string 'Designates that this user has all permissions without explicitly assigning them. '

Because this is the Django defined User class, I'm not sure 'verbose_name' would help. Or at least I don't know how to do it in that case.

Hope you guys can help.

Thanks for reading.

Upvotes: 0

Views: 789

Answers (2)

Christian Abbott
Christian Abbott

Reputation: 6977

This can be done by overriding get_form() on a customized subclass of django's UserAdmin, as follows:

# admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

class MyUserAdmin(UserAdmin):
    def get_form(self, request, obj, **kwargs):
        form = super(MyUserAdmin, self).get_form(request, obj, **kwargs)
        form.base_fields['is_superuser'].label = 'My label'
        form.base_fields['is_superuser'].help_text = 'My help text'
        return form

# NOTE: You may need to unregister the existing UserAdmin 
# before registering this custom one
admin.site.register(User, MyUserAdmin)

Note that get_form() returns a form that doesn't have a fields attribute, which is why you access base_fields. For a change as minor as the label and help_text, modifying base_fields is, as Douglas Adams might say, mostly harmless.

Upvotes: 1

obayhan
obayhan

Reputation: 1732

A dirty way:

If u use virtual enviroment u may change the related .po& .mo file directly in django folder in virtual enviroment. But then u can must lock the django version at least within the requirements file aginst overwriting.

Upvotes: 0

Related Questions