如何在Django admin中显示带有list_display的已分配组?

时间:2015-10-12 19:19:56

标签: python django

如何在admin.py中使用list_display的用户显示已分配的群组?

class usr_fields(admin.ModelAdmin):
    list_display = ('')

1 个答案:

答案 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'