'Send notification on changes ManyToMany field (needs to be handled separately due to Django design)'

def send_notifcations_on_m2m(self, user, request, sender, instance, action, reverse, model, pk_set, **kwargs):

    if isinstance(instance, Object):
        attr = sender._meta.object_name.split('_', 1)[1]
        if (attr in settings.HARDTREE_OBJECT_BLACKLIST):
            return
        if ((action == 'pre_clear') or (action == 'pre_remove')):
            original = list(getattr(instance, attr).all())
            self.objects[unicode(user.id)].update({unicode(instance.id): original})
        elif ((action == 'post_add') or (action == 'post_remove')):
            updated = list(getattr(instance, attr).all())
            if ((unicode(user.id) in self.objects) and (unicode(instance.id) in self.objects[unicode(user.id)])):
                original = self.objects[unicode(user.id)][unicode(instance.id)]
                if (not (original == updated)):
                    try:
                        instance.create_notification('m2m', user, field=attr, original=original, updated=updated)
                    except:
                        pass
                del self.objects[unicode(user.id)][unicode(instance.id)]
    elif isinstance(instance, UpdateRecord):
        attr = sender._meta.object_name.split('_', 1)[1]
        if ((action == 'post_add') and (attr == 'about')):
            obj_query = model.objects.filter(pk__in=pk_set)
            subscribers = set()
            if instance.author:
                contact = instance.author.get_contact()
                if contact:
                    subscribers.update(contact.subscribers.all())
                subscribers.add(instance.author)
            for obj in obj_query:
                subscribers.update(obj.subscribers.all())
            for subscriber in subscribers:
                instance.recipients.add(subscriber)
            for obj in obj_query:
                instance.notify_subscribers(obj, request=request)
