Пример #1
0
    @classmethod
    def delete_related(cls, ref_type, ref_pk):
        deleted = 0
        query = cls.objects.filter(ref_type=ref_type, ref_pk=str(ref_pk))
        for instance in query:
            instance.delete()
            deleted += 1
        return deleted


#---------------------------------------------------------------------------------------------------


def delete_related_comments(sender, **kwargs):
    if sender != Comment:
        try:
            instance = kwargs["instance"]
            deleted = Comment.delete_related(ref_type=sender.__name__, ref_pk=instance.pk)
            if deleted > 0:
                logging.info("%s related comments have been deleted successfully." % deleted)
        except Exception, exc:
            logging.error("Failed to delete related comments on instance: %s" % exc)
            logging.exception(exc)


pre_delete.connect(delete_related_comments)


# EOF
Пример #2
0
    @classmethod
    def delete_related(cls, activity):
        deleted = 0
        query = cls.objects.filter(activity=activity)
        for instance in query:
            instance.delete()
            deleted += 1
        return deleted


#---------------------------------------------------------------------------------------------------


def delete_related_attenders(sender, **kwargs):
    if sender == Activity:
        try:
            activity = kwargs["instance"]
            deleted = Attender.delete_related(activity=activity)
            if deleted > 0:
                logging.info("%s related attenders have been deleted successfully." % deleted)
        except Exception, exc:
            logging.error("Failed to delete related attenders of activity: %s" % exc)
            logging.exception(exc)


pre_delete.connect(delete_related_attenders, sender=Activity)


# EOF
Пример #3
0
    @classmethod
    def delete_related(cls, resto):
        deleted = 0
        query = cls.objects.filter(resto=resto)
        for instance in query:
            instance.delete()
            deleted += 1
        return deleted


#---------------------------------------------------------------------------------------------------


def delete_related_dishes(sender, **kwargs):
    if sender == Resto:
        try:
            resto = kwargs["instance"]
            deleted = Dish.delete_related(resto=resto)
            if deleted > 0:
                logging.info("%s related dishes have been deleted successfully." % deleted)
        except Exception, exc:
            logging.error("Failed to delete related dishes on resto: %s" % exc)
            logging.exception(exc)


pre_delete.connect(delete_related_dishes, sender=Resto)


# EOF
Пример #4
0
def delete_related_fans(sender, **kwargs):
    if sender != Fan:
        try:
            instance = kwargs["instance"]
            deleted = Fan.delete_related(ref_type=sender.__name__, ref_pk=instance.pk)
            if deleted > 0:
                logging.info("%s related fans have been deleted successfully." % deleted)
        except Exception, exc:
            logging.error("Failed to delete related fans of instance: %s" % exc)
            logging.exception(exc)


def delete_related_faves(sender, **kwargs):
    if sender != Fave:
        try:
            instance = kwargs["instance"]
            deleted = Fave.delete_related(ref_type=sender.__name__, ref_pk=instance.pk)
            if deleted > 0:
                logging.info("%s related faves have been deleted successfully." % deleted)
        except Exception, exc:
            logging.error("Failed to delete related faves of instance: %s" % exc)
            logging.exception(exc)


pre_delete.connect(delete_related_fans)
pre_delete.connect(delete_related_faves)


# EOF