I’m developing a system where users will need to match model fields from several models. To assist them, I’ve created an “is_orphan” Boolean field to indicate whether the required relationship (ForeignKey, in this case) should exist but doesn’t yet. It is updated as part of the save routine – example below:
class Caption(models.Model):
caption = models.TextField()
is_orphan = models.BooleanField()
def save(self, *args, **kwargs):
art_set = self.art_set.all()
if len(art_set) != 0:
self.is_orphan = False
else:
self.is_orphan = True
super(Caption, self).save(*args, **kwargs)
My problem is that when I use the admin to release the caption from the other side of the relationship (Art), the change in orphan status for the Caption isn’t reflected unless I go through the Caption save routine. Is there a way to automatically update caption.is_orphan from within the Art model whenever the user changes the caption associated art to a new caption, or no caption at all?
In the
savemethod of Art model: