From 30874ad832263ff3c8c58d54892f5479f01fccc7 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 16 May 2016 17:03:58 -0400 Subject: [PATCH] handle toggling of active --- core/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/models.py b/core/models.py index 3f65ec6c..3ad00c88 100755 --- a/core/models.py +++ b/core/models.py @@ -2062,10 +2062,16 @@ class Ebook(models.Model): def set_free_flag(sender, instance, created, **kwargs): if created: - if not instance.edition.work.is_free: + if not instance.edition.work.is_free and instance.active: instance.edition.work.is_free = True instance.edition.work.save() - + elif not instance.active and instance.edition.work.is_free==True and instance.edition.work.ebooks().count()==0: + instance.edition.work.is_free = False + instance.edition.work.save() + elif instance.active and instance.edition.work.is_free==False and instance.edition.work.ebooks().count()>0: + instance.edition.work.is_free = True + instance.edition.work.save() + post_save.connect(set_free_flag,sender=Ebook) def reset_free_flag(sender, instance, **kwargs):