no cyclic reference possible

This commit is contained in:
Qwann 2018-08-09 15:11:20 +02:00
parent 174e62b316
commit ec8e289ff8

View file

@ -30,6 +30,20 @@ class EquipmentCategory(models.Model):
def __str__(self):
return self.name
def save(self, *args, **kwargs):
if self.pk:
done = False
current = self
while not done:
if current.parent == self:
self.parent = None
done = True
elif current.parent == None:
done = True
current = current.parent
return super().save(*args, **kwargs)
class Equipment(EventSpecificMixin, models.Model):
name = models.CharField(