bbs-admin-自定义admin(二)
本文内容
目的:模仿admin默认配置,自定义配置类
一 查
1 查看数据
2 查看表头
3 分页器
4 search(搜索框)
5 action(批量处理)
6 filter(分类)
7 pop (弹出框)
二 增删改
查
1 查看数据
操作
class ModelStark: list_display = ['__str__'] def __init__(self,model): self.model = model def show(self,request): show_obj = self.model.objects.all() # 构建数据 list_date=[] for obj in show_obj: ret0=[] for field in self.list_display: ret = getattr(obj,field) ret0.append(ret) list_date.append(ret0) return render(request,'show.html',{'list_date':list_date,'list_tole':list_tole})
2 查看表头
操作
class ModelStark: list_display = ['__str__'] def __init__(self,model): self.model = model def show(self,request): print('>>>>>>>',self.model,self.list_display) show_obj = self.model.objects.all() # 构建表头 list_tole=[] for field in self.list_display: field_obj = self.model._meta.get_field(field) list_tole.append(field_obj.verbose_name) return render(request,'show.html',{'list_date':list_date,'list_tole':list_tole})