def has_active_relation(model_instance):
    """
    Returns True if at least one other model instance has a relationship with this instance
    Intended to be used to determine if this object can safely be deleted without any consequential cascade deletions
    Customised version of https://stackoverflow.com/questions/26659023/deletion-objects-that-is-used-as-foreign-key and https://gist.github.com/vonorm/8617378
    """
    for field in model_instance._meta.get_fields():
        if field.related_model:
            related = field.related_model.objects.filter(**{field.field.
                name: model_instance})[:1].values_list('pk', flat=True)
            if len(related) > 0:
                return True
    return False
