Django how to make ul li hierachy from a self reference model
问题 i have a model like this class Unit(models.ModelForm): Name = models.CharField(max_length = 100) Parent = models.ForeignKey('self' , on_delete=models.CASCADE , related_name = 'SubUnits') i want to show hierarchy tree with ul and li in the template. first of all in the views.py i passed all Units with no parent which considered as Root Objects and then with a custom filter tag i want to generate hierarchy ul li tree object1 ----|object 1.1 |object 1.2------| object 1.2.1 |object 1.3 objecte 2