Replaced query with sqlalchemy relationship