This sqlalchemy code should really be encapsulated in the resource views model