这是我的模特:
class Company(models.Model):
class Meta:
verbose_name_plural = "companies"
name = models.CharField(max_length=30)
parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL)
def __str__(self):
return 'Company: %s' % self.name
是否有办法修改def __str__
方法以显示具有-
或缩进的子项,具体取决于与其父级的关系?像这样:
Company A
- Company C
Company B
- Company D
- Company E
-- Company F