'Can I change model admin verbose name based on user group login in django?

I am aware of the Model Meta tag to specify the verbose_name, verbose_name_plural. But require the verbose name in model admin based on user login based on the group he is in. How can we override this attribute?



Solution 1:[1]

The best way to do this will be overriding AdminSite in admin.py file

Here is an example to do this

from django.contrib.admin import AdminSite

class MyAdminSite(AdminSite):
    def each_context(self, request):
        already_dict = super().each_context(request)
        for name in already_dict['available_apps']:
            # here you can access current user as request.user
            # you can change model name with name['models'][0]['name'] = 'some name you want'
            print(name['models'])
        return already_dict


admin.site = MyAdminSite()
admin.site.register(YourModelName)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Deepak Tripathi