add signal reciever to set partner.specific_stream=False after last related stream is deleted.
@@ -14,6 +14,9 @@ from django.core.urlresolvers import reverse_lazy, reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_countries.fields import CountryField
+from django.dispatch import receiver
+from django.db.models.signals import post_delete
+
RESOURCE_LANGUAGES = copy.copy(settings.INTERSECTIONAL_LANGUAGES)
@@ -671,6 +674,18 @@ class Stream(models.Model):
return access_url
+@receiver(post_delete, sender=Stream)
+def set_partner_specific_stream_false_if_no_streams(sender, instance, **kwargs):
+ """
+ Set parent partner's specific_stream to False when the last stream is deleted.
+ """
+
+ partner = instance.partner
+ if Stream.objects.filter(partner=partner).count() == 0:
+ partner.specific_stream = False
+ partner.save()
+
+
class Contact(models.Model):
"""
A Partner may have one or more contact people. Most of this information is
