在model模块里设置
class pc_info(models.Model):
ip = models.CharField(max_length=64)
sn = models.CharField(max_length=64)
addr = models.CharField(max_length=64)
room_num = models.CharField(max_length=64)
pc_type = models.CharField(max_length=64)
brand = models.CharField(max_length=64)
chest_num = models.CharField(max_length=64)
disk_num = models.CharField(max_length=64)
disk_pn = models.CharField(max_length=64)
single_disk_size = models.CharField(max_length=64)
out_ip = models.CharField(max_length=64)
comment = models.CharField(max_length=64)
def __str__(self): #定义标题
return self.ip
def address(self): #定义标题
return self.addr
address.short_description = ‘地区‘ #后排管理显示中文标题
address.admin_order_field = ‘addr‘ #可以点击定义的addr的标题排序
在admin.py里设置
from cmdb.models import pc_info #从models模块里导入表的类名
# Register your models here.
class pc_infoAdmin(admin.ModelAdmin):
list_per_page = 15 #一页显示15行数据
list_display = [‘ip‘, ‘address‘, ‘room_num‘] #要显示的标题
admin.site.register(pc_info, pc_infoAdmin) #注册
原文地址:https://www.cnblogs.com/fengzi7314/p/9636483.html