我有任务层次结构。我想建一棵树。现在我可以构建树了,但我有重复的任务。如何检查任务是否已显示? 现在我有了这段代码:
template.html
<ul>
{%for task in tasks %}
{%include "tree.html" %}
{%endfor%}
</ul>
tree.html
<li>{{task.name}}</li>
<ul>
{%for ch in task.children.all %}
{%with task=ch template_name="tree.html" %}
{%include template_name%}
{%endwith%}
{%endfor%}
</ul>
</li>
类任务模型
class Task(models.Model):
name = models.CharField(max_length=200)
parent = models.ForeignKey('self', null=True, blank=True,
related_name='children')