标签:mod html title inner request 无限级 测试 parent 建模
class AreaInfo(models.Model):
atitle = models.CharField(max_length=20)
aParent = models.ForeignKey(‘self‘, null=True, blank=True)
上级对象:area.aParent
下级对象:area.areainfo_set.all()
from models import AreaInfo
def area(request):
area = AreaInfo.objects.get(pk=130100)
return render(request, ‘booktest/area.html‘, {‘area‘: area})
<!DOCTYPE html>
<html>
<head>
<title>地区</title>
</head>
<body>
当前地区:{{area.atitle}}
<hr/>
上级地区:{{area.aParent.atitle}}
<hr/>
下级地区:
<ul>
{ %for a in area.areainfo_set.all%}
<li>{{a.atitle}}</li>
{ %endfor%}
</ul>
</body>
</html>
urlpatterns = [
url(r‘^area/$‘, views.area, name=‘area‘)
]
标签:mod html title inner request 无限级 测试 parent 建模
原文地址:http://www.cnblogs.com/huwei934/p/6978599.html