Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Rename Group to Role

I'm required to use the word "Role" instead of "Group" in a Django project.

I tried i18n, but could make auth pick up the translation.

I also tried replacing django.contrib.auth with a myaqpp.auth where Group is called ``Role.

Which is the correct way to do this renaming?

like image 638
Apalala Avatar asked Feb 10 '23 02:02

Apalala


1 Answers

Is it just a question of displaying Role in the admin interface, instead of Group? In that case, you could easily create a proxy model:

model:

from django.contrib.auth.models import Group
from django.utils.translation import ugettext_lazy as _


class Role(Group):
    class Meta:
        proxy = True
        app_label = 'auth'
        verbose_name = _('Role')

and then unregister the default Group model from the GroupAdmin and register your Role model instead:

from django.contrib.auth.admin import GroupAdmin
from django.contrib.auth.models import Group

from .models import Role


admin.site.unregister(Group)
admin.site.register(Role, GroupAdmin)

With all that said, I'd question the business decision forcing you to implement such a silly thing.

like image 158
Martin Tschammer Avatar answered Feb 22 '23 09:02

Martin Tschammer