Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite loop caused by ordering Django

When I try to delete a record from my model I have this error:

Infinite loop caused by ordering

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']

Thanks in advance

like image 472
user3791360 Avatar asked Dec 06 '25 08:12

user3791360


1 Answers

have you tried to use self ?

 parent = TreeForeignKey('self', blank=True, null=True, related_name='children'

and remove

`ordering = ['parent__id']`
like image 197
sax Avatar answered Dec 07 '25 22:12

sax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!