本文介绍了隐藏Django管理员网站中不同用户的某些字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我的模型看起来像
$ $
name = models.CharField(max_length = 100)
credit_card_number = models.CharField(max_length = 100)
管理员网站框架中是否有一种方法可以让超级用户看到信用卡号码?在管理网站框架中,我只能看到添加,编辑和删除的功能。
解决方案
创建方法 YouTube .get_cc_root_only ,您要检查用户是否是root用户,并在YouTubeAdmin类中使用( list_display )
更新:
class XyzAdmin(admin.ModelAdmin):
def get_cc_root_only(self,obj) :
如果self.username ==admin:
返回CC
返回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)
I have an admin site that I need to open up to more admins.
Currently my model looks like
class YouTube(models.Model):
name = models.CharField(max_length=100)
credit_card_number = models.CharField(max_length=100)
Is there a way in the admin site frame work to make it so that only superusers can see the credit card number? In the admin site framework, I can only see the ability to add, edit, delete.
解决方案
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")
这篇关于隐藏Django管理员网站中不同用户的某些字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!