I am using Flask and SQLAlchemy. I have a Person model and I want an attribute which returns the Person's full name (first + last).
I tried using @declared_attr, but it outputs:
"person.first_name || :param_1 || person.last_name"
Here is my code:
class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key = True)
type = Column(String(50))
first_name = Column(String(120), index = True)
last_name = Column(String(120), index = True)
@declared_attr
def name(cls):
"Returns Person's full name."
return cls.first_name + ' ' + cls.last_name