众所周知,许多关系无法在list_display中列出。是否有任何解决方法可以使其类似于group1,group2等?
最佳答案
我不理解您的示例(group1,group2),但是您当然可以在更改 ListView 中将任何函数用作列,这意味着您很可能可以执行要显示的内容!
例子:
class MyModelAdmin(admin.ModelAdmin):
list_display = ('foo', 'bar')
def foo(self):
return "This column is Foo"
def bar(self, obj):
try:
return obj.m2m.latest('id')
except obj.DoesNotExist:
return "n/a"
# there's a few more things you can do to customize this output
def bar(self, obj):
return '<span style="color:red;">By the way, I am red.</span>'
bar.short_description = "My New Column Label"
bar.allow_tags = True
关于django - Django-用户管理员-将组添加到list_display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5224828/