Python 具有具体继承的基础实体

Python 具有具体继承的基础实体,python,sqlalchemy,python-elixir,Python,Sqlalchemy,Python Elixir,我希望有一个带有字段deleted的基本实体,该字段标记已删除的记录。我有2个子类,每个子类都有自己的表和所有列: from elixir import * from sqlalchemy import create_engine class Catalog(Entity): using_options(inheritance='concrete') deleted = Boolean class Contact(Catalog): using_options(in

我希望有一个带有字段
deleted
的基本实体,该字段标记已删除的记录。我有2个子类,每个子类都有自己的表和所有列:

from elixir import *
from sqlalchemy import create_engine


class Catalog(Entity):
    using_options(inheritance='concrete')
    deleted = Boolean

class Contact(Catalog):
    using_options(inheritance='concrete')
    name = Field(String(60))

class Location(Catalog):
    using_options(inheritance='concrete')
    name = Field(String(100))

setup_all()

metadata.bind = create_engine('sqlite:///', echo=True)
metadata.create_all()
结果是:

CREATE TABLE __main___catalog (
        id INTEGER NOT NULL, 
        PRIMARY KEY (id)
)

CREATE TABLE __main___contact (
        id INTEGER NOT NULL, 
        name VARCHAR(60), 
        PRIMARY KEY (id)
)

CREATE TABLE __main___location (
        id INTEGER NOT NULL, 
        name VARCHAR(100), 
        PRIMARY KEY (id)
)
问题:

  • 如何避免为基本实体创建表?-已解决:
    使用_选项(abstract=True)
  • 为什么字段
    已删除
    不在创建的表中?-这个问题解决了-我忘了把它放在
    字段中
  • 我希望避免使用_options(heritation='concrete')在每个子类
    中键入内容,但仍然有“concrete heritation”。有没有一种方法可以使它成为所有子类的默认值
  • 这项工作:

    class Catalog(Entity):
    
        deleted = Field(Boolean)
        using_options(abstract = True, inheritance = 'concrete')        
    
    
    class Contact(Catalog):
    
        name = Field(String(60))
    
    
    class Location(Catalog):
    
        name = Field(String(100))
    
    并创建以下表:

    CREATE TABLE __main___contact (
            id INTEGER NOT NULL, 
            deleted BOOLEAN, 
            name VARCHAR(60), 
            PRIMARY KEY (id), 
            CHECK (deleted IN (0, 1))
    )
    
    CREATE TABLE __main___location (
            id INTEGER NOT NULL, 
            deleted BOOLEAN, 
            name VARCHAR(100), 
            PRIMARY KEY (id), 
            CHECK (deleted IN (0, 1))
    )