diff --git a/aircox/models/program.py b/aircox/models/program.py index 27d8a8e..d0bd2ee 100644 --- a/aircox/models/program.py +++ b/aircox/models/program.py @@ -86,6 +86,7 @@ class Program(Page): super().__init__(*kargs, **kwargs) if self.slug: self.__initial_path = self.path + self.__initial_cover = self.cover @classmethod def get_from_path(cl, path): @@ -133,6 +134,7 @@ class Program(Page): super().save(*kargs, **kwargs) + # TODO: move in signals path_ = getattr(self, '__initial_path', None) if path_ is not None and path_ != self.path and \ os.path.exists(path_) and not os.path.exists(self.path): diff --git a/aircox/models/signals.py b/aircox/models/signals.py index c2ccd57..9209672 100755 --- a/aircox/models/signals.py +++ b/aircox/models/signals.py @@ -56,6 +56,13 @@ def program_post_save(sender, instance, created, *args, **kwargs): Episode.object.parent(instance).filter(diffusion__isnull=True) \ .delete() + cover_ = getattr(instance, '__initial_cover', None) + if cover_ is None and instance.cover is not None: + Episode.objects.parent(instance) \ + .filter(cover__isnull=True) \ + .update(cover=instance.cover) + + @receiver(signals.pre_save, sender=Schedule) def schedule_pre_save(sender, instance, *args, **kwargs):