improve python3 compatibility
correct query_class handling for Flask-SQLAlchemy models