I want to return a custom property from flask restless such as
class Item(db.Model):
creator_id = db.Column(db.Integer, db.ForeignKey('User.id'))
owner_id = db.Column(db.Integer, db.ForeignKey('User.id'))
owner = db.relationship("User",backref="items",primary_join="Item.owner_id==User.id")
owner = db.relationship("User",backref="created_items",primary_join="Item.creator_id==User.id")
class User(db.Model):
id = db.Column(db.Integer, primary_key = True)
firstName = db.Column(db.Unicode(50), nullable = False)
lastName = db.Column(db.Unicode(50), nullable = False)
email = db.Column(db.Unicode(100), nullable = False)
I’d like to be able to return firstName + ” ” + lastName in the item for the creator in the
/api/User/1 for flask-restless
You can’t really do this without modifying flask-restless. If you look in the flask-restless source, in
views.py, the method_to_dictexplicitly iterates over properties of the object and only includes ones that are instances of SQLAlchemy’sColumnPropertytype.That function would be the place to start, change that code to include properties of some other type, and then add a property to your
Userclass that concatenatesfirstNameandlastName.