def _switch_instances_is_active(instances, new_state):
    """ For all objects in the 'instances' list, if 'is_active' is present set it to new_state"""
    for inst in instances:
        if hasattr(inst, 'is_active') and inst.is_active is not new_state:
            inst.is_active = new_state
            inst.save()
