当我尝试从模型中删除记录时出现此错误:
订购导致的无限循环
class Empresa(MPTTModel):
nombre = models.CharField(max_length=35, unique=True, db_index=True)
parent = TreeForeignKey('Empresa', blank=True, null=True, related_name='children')
nivel = models.PositiveIntegerField(default=1)
class MPTTMeta:
order_insertion_by = ['nivel']
class Meta:
ordering = ['parent__id']
提前致谢
答案 0 :(得分:1)
您是否尝试过使用self
?
parent = TreeForeignKey('self', blank=True, null=True, related_name='children'
并删除
`ordering = ['parent__id']`