【问题标题】:Django Admin, how to replace the user status signDjango Admin,如何替换用户状态标志
【发布时间】:2016-08-15 07:35:03
【问题描述】:

在 django admin 中,超级用户一栏,显示这两个标志

如何用文本替换它们?

【问题讨论】:

  • 如果您显示一些代码会有所帮助。您如何显示超级用户列?默认不显示。
  • list_display = ('username', 'first_name', 'email', 'date_joined', 'is_superuser',)

标签: django python-3.x django-admin


【解决方案1】:

您可以定义返回所需文本的模型管理方法,然后将其包含在list_display 中。

class MyUserAdmin(UserAdmin):
    def is_superuser_text(self, obj):
        return 'True' if obj.is_superuser else 'False'            
    is_superuser_text.short_description = 'Is Superuser'
    is_superuser_text.admin_order_field = 'is_superuser'

    list_display = ('username', 'first_name', 'email', 'date_joined', 'is_superuser_text',)

【讨论】:

  • 这很好用,谢谢,但订购被禁用;我怎样才能再次启用它?
  • 设置admin_order_field.
  • 它成功了,但是当我点击它时,我得到这个 ''tuple' 对象没有属性 'startswith'' 错误。
  • 听起来你打错了
猜你喜欢
  • 1970-01-01
  • 2018-04-05
  • 2020-08-23
  • 2017-06-14
  • 1970-01-01
  • 1970-01-01
  • 2018-08-13
  • 2015-07-12
  • 1970-01-01
相关资源
最近更新 更多