Hide certain fields in Django admin site for different user

断了今生、忘了曾经 提交于 2019-12-06 07:38:39

Create method YouTube.get_cc_root_only, where you are to check if user is root, and use it in YouTubeAdmin class (list_display)

UPDATED:

class XyzAdmin(admin.ModelAdmin):
    def get_cc_root_only(self, obj):
        if self.username == "admin":
            return "CC"
        return "XXX"

    def changelist_view(self, request, extra_context = None):
        self.username = request.user.username
        return super(XyzAdmin,self).changelist_view(request, extra_context = extra_context)

    list_display = ("name", "get_cc_root_only")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!