django admin中的list_display设置了,但是页面没有显示出来列

django admin中的list_display设置了,但是页面没有显示出来列

  • 存在问题
  • project\myApp\admin.py
            • #Register your models here.
            • #注册
    • 解决办法
            • #Register your models here.
            • #注册
    • 最终实现

存在问题

django admin中的list_display设置了,但是页面没有显示出来列

project\myApp\admin.py

原code
from django.contrib import admin

#Register your models here.

from .models import Grades,Students

#注册

class GradesAdmin(admin.ModelAdmin):
# 列表属性
list_display = [‘pk’,‘gname’,‘gdate’,‘ggirlnum’,‘gboynum’,‘isDelete’]
list_filter = [‘gname’]
search_fields = [‘gname’]
list_per_page = 5

# 添加、修改页属性
#fields = ['ggirlnum','gboy','gname','gdate','isDelete']
fieldsets = [
    ("num",{"fields":['ggirlnum','gboynum']}),
    ("base",{"fields":['gname','gdate','isDelete']}),
]

admin.site.register(Grades)
admin.site.register(Students)

解决办法

from django.contrib import admin

#Register your models here.

from .models import Grades,Students

#注册

class GradesAdmin(admin.ModelAdmin):
# 列表属性
list_display = [‘pk’,‘gname’,‘gdate’,‘ggirlnum’,‘gboynum’,‘isDelete’]
list_filter = [‘gname’]
search_fields = [‘gname’]
list_per_page = 5

# 添加、修改页属性
#fields = ['ggirlnum','gboy','gname','gdate','isDelete']
fieldsets = [
    ("num",{"fields":['ggirlnum','gboynum']}),
    ("base",{"fields":['gname','gdate','isDelete']}),
]

admin.site.register(Grades,GradesAdmin)
admin.site.register(Students)

把新的类GradesAdmin添加到admin.site.register()中

最终实现

django admin中的list_display设置了,但是页面没有显示出来列_第1张图片

你可能感兴趣的:(学习)