def session_query(session, model):
 if hasattr(model, 'query'):
  if callable(model.query):
   query = model.query()
  else:
   query = model.query
  if hasattr(query, 'filter'):
   return query
 return session.query(model)

def session_query ( session , model ) : if hasattr ( model , 'query' ) : if callable ( model . query ) : query = model . query ( ) else : query = model . query if hasattr ( query , 'filter' ) : return query return session . query ( model )
returns a sqlalchemy query object for the specified model .