考虑PostgreSQL 9.3数据库中的下表:
Table "public.text"
Column | Type | Modifiers
------------+-----------------------------+------------------------
name | character varying(255) | not null
lang | character varying(3) | not null
text | character varying(255) |
time_stamp | timestamp without time zone | not null default now()
Indexes:
"text_pkey" PRIMARY KEY, btree (name, lang)
该表由以下Python类使用SQLALchemy Base建模:
class Text(Base):
__tablename__ = 'text'
__table_args__ = (PrimaryKeyConstraint(name, lang),)
name = Column(String(255))
lang = Column(String(3))
text = Column(String(255))
time_stamp = Column(Date)
def __init__(self, name, lang, text):
self.name = name
self.lang = lang
self.text = text
...
班级成员(name
,lang
,text
,time_stamp
)的标识符与数据库表的标识符相同。
如何定义具有不同成员标识符的类,这些标识符将映射到现有表列?例如,我想将Text.langugage
映射到表格列lang
。
答案 0 :(得分:2)