🎨 Auto-prefix table_names with "{app_label}_"
There is no support for auto-prefixing implicit proxy-tables in Tortoise. If you need to prefix a proxy-table, explicitly define the Model for the proxy table. Being an explicit model, it will then be auto-prefixed.
This commit is contained in:
parent
acd4844a25
commit
ce47e3f60e
1 changed files with 12 additions and 0 deletions
|
|
@ -31,6 +31,18 @@ UUID.__get_pydantic_core_schema__ = classmethod(__uuid_schema_monkey_patch)
|
|||
|
||||
class ModelMeta(type(TortoiseModel)):
|
||||
def __new__(mcls, name, bases, attrs):
|
||||
meta = attrs.get("Meta", None)
|
||||
if meta is None:
|
||||
class Meta:
|
||||
pass
|
||||
meta = Meta
|
||||
attrs["Meta"] = meta
|
||||
|
||||
if not hasattr(meta, "table"):
|
||||
# Use first part of module as app_label
|
||||
app_label = attrs.get("__module__", "").replace("ohmyapi.builtin.", "ohmyapi_").split(".")[0]
|
||||
setattr(meta, "table", f"{app_label}_{name.lower()}")
|
||||
|
||||
# Grab the Schema class for further processing.
|
||||
schema_opts = attrs.get("Schema", None)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue