I am trying to write a class for substances which has a name filed (for the name, as commonly used in the lab) and another column for the long name (in case the name is actually incomplete). Is there some wy to tell the class to just copy the value of the name field to the long name field in case a long name is not specified?
I tried something like this:
class Substance(Base):
__tablename__ = "substances"
id = Column(Integer, primary_key=True)
code = Column(String, unique=True)
name = Column(String, unique=True)
long_name = Column(String, unique=True, default=name)
But this fails, since name
is undefined. Is there anything else I could do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…