-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
52 lines (41 loc) · 1.34 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from django.contrib import admin
# Register your models here.
from .models import Students,Grades
class StudentInfo(admin.TabularInline):
model=Students
extra=2
class GradesAdmin(admin.ModelAdmin):
#创建类型时添加子类型
inlines=[StudentInfo]
#列表页属性
#1.显示字段
list_display = ['pk','gname','gdate','ggirlnum','gboynum','isDelete']
#2.添加过滤器
list_filter = ['gname']
#3.添加查找器
search_fields = ['gname']
#分页功能
list_per_page =5
#添加,修改页属性
#1.改变顺序
#fields =['ggirlnum','gboynum','gname','gdate','isDelete']
#2.给属性分组 fields与fieldsets不能同时使用
fieldsets =[
("num",{"fields":['ggirlnum','gboynum']}),
("base",{"fields":['gname','gdate','isDelete']})
]
admin.site.register(Grades,GradesAdmin)
class StudentAdmin(admin.ModelAdmin):
#运用函数修改布尔值
def gender(self):
if self.sgender:
return"男"
else:
return"女"
#修改列名称
gender.short_description = "性别"
list_display = ['pk', 'sname', 'sage', 'scontend', gender,'sgrade','isDelete']
list_per_page = 2
admin.site.register(Students,StudentAdmin)
from .models import text
admin.site.register(text)