django自制后台左侧导航代码

自定义一个sort.py页面:

写入一下代码:

class lanmusort(object):
def __init__(self):
self.arr=[] def lanmuget(self,obj):
for value in obj:
if value['pid']==0:
value['lists']=[]
self.arr.append(value)
self.lanmuget_two(obj,value['id'],value['lists'])
del obj
return self.arr
def lanmuget_two(self,obj,pid,lists):
for value in obj:
if value['pid'] == pid:
value['lists'] = []
lists.append(value)
self.lanmuget_two(obj,value['id'],value['lists'])
def __del__(self):
del self.arr

数据库查询页面

view.py:(引入上面的自定义页面)

# 输出左侧栏目列表
left_lanmu = models.AdminRule.objects.order_by('sort').all().values("id","title","name","sort","is_top","pagenumber","pid",)
re_left_lanmu = lanmu.lanmusort()
relanmu = re_left_lanmu.lanmuget(left_lanmu)
 
上一篇:【转】ASP.NET MVC 的最佳实践


下一篇:基于visual Studio2013解决C语言竞赛题之0204实数求值