如何在admin.py中使用list_display
的用户显示已分配的群组?
class usr_fields(admin.ModelAdmin):
list_display = ('')
答案 0 :(得分:0)
试试这个:
from django.contrib.auth.models import User
class usr_fields(admin.ModelAdmin):
class Meta:
model = User
list_display = ('get_groups')
def get_groups(self, obj):
return obj.groups.values_list('name',flat=True)
get_groups.short_description = 'Groups'