#!/usr/bin/python
# -*- coding:utf8 -*-
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
# Register your models here.
admin.site.site_header = 'Big Tager BackEnd'
admin.site.site_title = 'Big Tager BackEnd'
admin.site.index_title = 'Big Tager BackEnd'
# admin.site.register(User)
@admin.register(User)
class UserAdmin(UserAdmin):
list_display = ('id', 'username', 'phone')
ordering = (u'id',)
# fields里面的字段,是按行排列的,若想要某些字段展示再一行,用('is_superuser', 'is_staff', 'is_active')
fieldsets = (None, {'fields': (
'username', 'phone', 'password', 'groups',('is_superuser', 'is_staff', 'is_active'),)}),
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": ("username", 'phone','groups',"password1", "password2"),
},
),
)
readonly_fields = ('password',)
list_per_page = 5
# 增加自定义按钮
# actions = ['make_copy', 'custom_button']
def custom_button(self, request, queryset):
pass
# 显示的文本,与django admin一致
custom_button.short_description = '测试按钮'
# icon,参考element-ui icon与https://fontawesome.com
custom_button.icon = 'fas fa-audio-description'
# 指定element-ui的按钮类型,参考https://element.eleme.cn/#/zh-CN/component/button
# custom_button.type = 'danger'
# 给按钮追加自定义的颜色
custom_button.style = 'color:black;'
def make_copy(self, request, queryset):
pass
make_copy.short_description = '复制员工'
参考链接:
https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Django/Admin_site