fix: improve FK handling in generated model class code
also tweak default revision message for new table
This commit is contained in:
parent
2b5775b348
commit
34704acf24
2 changed files with 12 additions and 16 deletions
|
|
@ -15,16 +15,6 @@ 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__ = {}
|
||||
|
|
@ -48,17 +38,23 @@ class ${model_name}(model.Base):
|
|||
|
||||
% if column["name"] == "uuid":
|
||||
uuid = model.uuid_column()
|
||||
% 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"]:
|
||||
% elif column["data_type"]["type"] == "_fk_uuid_":
|
||||
${column["name"]} = model.uuid_fk_column("${column['data_type']['reference']}.uuid",
|
||||
nullable=${column["nullable"]})
|
||||
% if 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
|
||||
|
||||
|
|
|
|||
|
|
@ -947,7 +947,7 @@
|
|||
} else {
|
||||
this.modelImportProblem = false
|
||||
this.modelImported = this.modelImportName
|
||||
this.revisionMessage = `add table for ${"$"}{this.tableModelTitlePlural}`
|
||||
this.revisionMessage = `add ${"$"}{this.tableModelTitlePlural}`
|
||||
}
|
||||
}, 200)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue