How to use the aldjemy.table.generate_tables function in aldjemy

To help you get started, we’ve selected a few aldjemy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Deepwalker / aldjemy / aldjemy / orm.py View on Github external
def construct_models(metadata):
    if not metadata.tables:
        generate_tables(metadata)
    tables = metadata.tables
    models = [model for model in get_all_django_models() if not model._meta.proxy]

    sa_models_by_django_models = {}

    for model in models:

        table_name = (
            metadata.schema + '.' + model._meta.db_table
            if metadata.schema else model._meta.db_table
        )
        mixin = getattr(model, 'aldjemy_mixin', None)
        bases = (mixin, BaseSQLAModel) if mixin else (BaseSQLAModel, )
        table = tables[table_name]

        # because querying happens on sqlalchemy side, we can use only one