Search code examples
pythonsqlalchemymodelspyramidpylons

not able to get list of all models in a pyramid project


I am trying to write admin console for my pyramid project. I am trying to get a list of all classes defined in models. Is there any way to get these?


Solution

  • If you want to get list of all SQLAlchemy models you can do it through a registry exposed through Base class:

    models = {}
    
    for name, cls in Base._decl_class_registry.items():
    
        if name == "_sa_module_registry":
            continue
    
        models[name] = cls