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:
-
+
## main form
@@ -35,6 +34,7 @@
## rows grid +

${master.get_rows_title() or ''}

${rows_grid.render_vue_tag()}
diff --git a/src/wuttaweb/templates/tables/app/create.mako b/src/wuttaweb/templates/tables/app/create.mako index f8f8a57..ca82af9 100644 --- a/src/wuttaweb/templates/tables/app/create.mako +++ b/src/wuttaweb/templates/tables/app/create.mako @@ -818,7 +818,7 @@ } else if (dataType.type == 'UUID') { return `UUID()` } else if (dataType.type == '_fk_uuid_') { - return `UUID()` + return 'sa.String(length=32)' } else if (dataType.type == '_other_') { return dataType.literal } else { @@ -947,7 +947,7 @@ } else { this.modelImportProblem = false this.modelImported = this.modelImportName - this.revisionMessage = `add ${"$"}{this.tableModelTitlePlural}` + this.revisionMessage = `add table for ${"$"}{this.tableModelTitlePlural}` } }, 200) })