PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Python-Getter und -Setter über @property innerhalb der SqlAlchemy-Modellklassendefinition:HOWTO

Sie können hybrid_property verwenden .In diesem Fall sollte die vereinfachte Version Ihres Codes wie folgt aussehen:

from sqlalchemy.ext.hybrid import hybrid_property

class Transcriber(Base):
    __tablename__ = 'transcribers'
    __table_args__ = (
    UniqueConstraint('projectid', 'email'),
    )

    transcriberid = Column(Integer, primary_key=True, server_default=text("nextval('transcribers_transcriberid_seq'::regclass)"))
    projectid = Column(ForeignKey(u'projects.projectid', ondelete=u'CASCADE'), index=True)
    created = Column(DateTime, nullable=False, server_default=text("now()"))
    onwebsite = Column(Boolean, nullable=False, server_default=text("true"))

    _email = Column('email', Text, nullable=False)

    @hybrid_property
    def email(self):
        return self._email

    @email.setter
    def email(self, email):
        self._email = email