在您的基数模式中建立一套类型指标,以便作出更一般性的答复。 然后,使用这种类型标识而不是加以扼杀。
基地。 y
from sqlalchemy.types import TypeDecorator
class TruncateString(TypeDecorator):
"""trim spaces from the string"""
impl = db.String
cache_ok = True
def process_bind_param(self, value, dialect):
# In case you have nullable string fields and pass None
if value and len(value) > self.impl.length:
value = value[:self.impl.length]
return value if value else value
def copy(self, **kw):
return TruncateString(self.impl.length)
现在,在您的Model.py中,使用这种方式。
from flask_app.models.base import *
class CampaignScript(BaseModel):
__tablename__ = campaign_script
name = Column(TruncateString(200))
subject = Column(TruncateString(200))
comments = Column(TruncateString(200))
language = Column(TruncateString(200))
script = Column(NVARCHAR(None))
user_id = Column(TruncateString)
account_id = Column(Integer)
comm_type = Column(TruncateString(45))
short_name = Column(TruncateString(75))
released_locked = Column(Boolean())
good