首页 Django视频课程 django admin自定义函数处理字段内容
pay pay

django admin自定义函数处理字段内容

日期: 五月 25, 2023, 2:26 p.m.
栏目: Django视频课程
阅读: 151
作者: Python自学网-村长

摘要: django admin自定义函数处理字段内容

django admin自定义函数处理字段内容

def total_num(Grade):
    total = Grade.girl_num + Grade.boy_num
    return total
total_num.short_description = '总人数'

class GradeAdmin(admin.ModelAdmin):
    list_display = ['id', 'sub', 'boy_num', 'girl_num', total_num]
    list_filter = ['sub']
    list_display_links = ('sub',)


admin.site.register(Grade, GradeAdmin)
class PersonAdmin(admin.ModelAdmin):
    def sex_info(self):
        if self.sex:
            return '男'
        else:
            return '女'

    list_display = ['id', 'name', sex_info, 'age', 'info', 'is_del']
    list_filter = ['name']
    list_display_links = ('name',)


admin.site.register(Person, PersonAdmin)

 

原创视频,版权所有,未经允许,切勿转载,违者必究!
回顶部