diff --git a/src/wuttaweb/code-templates/new-table.mako b/src/wuttaweb/code-templates/new-table.mako index 15eead9..046862f 100644 --- a/src/wuttaweb/code-templates/new-table.mako +++ b/src/wuttaweb/code-templates/new-table.mako @@ -15,6 +15,16 @@ class ${model_name}(model.Base): ${description} """ __tablename__ = "${table_name}" + % if any([c["data_type"]["type"] == "_fk_uuid_" for c in columns]): + __table_args__ = ( + % for column in columns: + % if column["data_type"]["type"] == "_fk_uuid_": + sa.ForeignKeyConstraint(["${column['name']}"], ["${column['data_type']['reference']}.uuid"], + name="${table_name}_fk_${column['data_type']['reference']}"), + % endif + % endfor + ) + % endif % if versioned: % if all([c["versioned"] for c in columns]): __versioned__ = {} @@ -38,23 +48,17 @@ class ${model_name}(model.Base): % if column["name"] == "uuid": uuid = model.uuid_column() - % elif column["data_type"]["type"] == "_fk_uuid_": - ${column["name"]} = model.uuid_fk_column("${column['data_type']['reference']}.uuid", - nullable=${column["nullable"]}) - % if column["relationship"]: + % else: + ${column["name"]} = sa.Column(${column["formatted_data_type"]}, nullable=${column["nullable"]}, doc=""" + ${column["description"] or ""} + """) + % if column["data_type"]["type"] == "_fk_uuid_" and column["relationship"]: ${column["relationship"]["name"]} = orm.relationship( "${column['relationship']['reference_model']}", doc=""" ${column["description"] or ""} """) % endif - % else: - ${column["name"]} = sa.Column( - ${column["formatted_data_type"]}, - nullable=${column["nullable"]}, - doc=""" - ${column["description"] or ""} - """) % endif % endfor diff --git a/src/wuttaweb/templates/master/view.mako b/src/wuttaweb/templates/master/view.mako index b341012..08615f3 100644 --- a/src/wuttaweb/templates/master/view.mako +++ b/src/wuttaweb/templates/master/view.mako @@ -21,8 +21,7 @@ % if master.has_rows: