SQLAlchemy类有类变量不是实例变量?

2024-06-16 11:41:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一些域类,比如:

class Klient(Base):
    __tablename__ = 'klient'
    __table_args__ = (
        Index('pg_klient_index', 'nums', 'sals', 'k_id'),
    )
    def __init__(self):
        self.dogovors=list()
    adrrab = Column(String(200))
    c1uid = Column(String(45))
    cods = Column(String(10))
    d_first = Column(Date)
    d_vidan = Column(Date)
    docum = Column(String(40))
    doljn = Column(String(160))
    id = Column(BigInteger, primary_key=True, server_default=text("nextval('klient_id_seq'::regclass)"))
    inn = Column(String(15))
    izm = Column(Date)
    k_id = Column(BigInteger, nullable=False)
    .....
    vidan = Column(String(300))
    xmldat = Column(Date)
    xmlnum = Column(String(15))
    zak = Column(Numeric(1, 0))
    dogovors = []

我选择所有带代码的记录:

^{pr2}$

我看到了意想不到的行为:

enter image description here

enter image description here

enter image description here

每一个对象都有一个相同的dogover实例怎么可能?在

升级版:

我试着写:

class Klient(Base):
    __tablename__ = 'klient'
    __table_args__ = (
        Index('pg_klient_index', 'nums', 'sals', 'k_id'),
    )
    def __init__(self):
        self.dogovors=list()
    adrrab = Column(String(200))
    c1uid = Column(String(45))

但是我有个错误AttributeError: 'Klient' object has no attribute 'dogovors'


Tags: selfidbasedatestringindextableargs