我的模板接收一个名为 categories 的变量,我想列出其父类别的“儿子”类别
这是我在模板中的代码
{% for category,structure in categories|tree_info %}
{% if structure.new_level %}
<li><a href="/categories/{{ category.id }}/">{{ category.name }}</a> </li>
{% endif %}
{% for level in structure.closed_levels %}
<li>{{level.name}}
{% endfor %}
<ul class="noJS">
{% for cat in category.get_children|tree_info %}
<li><a href="/categories/{{ cat.id }}/">{{ cat.name }}aa</a> </li>
{% endfor %}
</ul>
{% endfor %}
这是模型
class Category(MPTTModel):
name = models.CharField(max_length=50, unique=True)
description = models.TextField(blank=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
class MPTTMeta:
order_insertion_by = ['name']
def __unicode__(self):
return self.name
任何的想法?