Fixes #20912: Clear ModuleBay parent when module assignment removed

When a ModuleBay's module field is cleared (returning it to device-level),
the parent field was not being updated, leaving stale MPTT tree data.

The save() method only set parent when module was present, but failed to
clear it when module was removed. Now explicitly sets parent to None when
module is cleared.
This commit is contained in:
Jason Novinger
2025-12-12 10:52:07 -06:00
parent 21f4036782
commit 413be72f73
2 changed files with 28 additions and 0 deletions

View File

@@ -1222,6 +1222,8 @@ class ModuleBay(ModularComponentModel, TrackingModelMixin, MPTTModel):
def save(self, *args, **kwargs):
if self.module:
self.parent = self.module.module_bay
else:
self.parent = None
super().save(*args, **kwargs)