def get_or_create(cls, session, **filters):
    """Retrieve or add object; return a tuple ``(object, is_new)``.
    ``is_new`` is True if the object already exists in the database.
    """
    instance = session.query(cls).filter_by(**filters).first()
    is_new = not instance
    if is_new:
        instance = cls(**filters)
    return instance, is_new