[Django]-Hide certain fields in Django admin site for different user

3👍

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")

Leave a comment