Reputation: 125
I have a table representing a phone call and want to store that data
from app.db import db
from app.schema import ma
#db = SQLAlchemy()
class phoneCall(db.Model):
__tablename__ = "phoneCalls"
callerid = db.Column(db.String, primary_key=True)
#from = db.Column(db.String)
_from = db.Column("from", db.String)
to = db.Column(db.String)
duration = db.Column(db.Integer)
#ma = flask_marshmallow.Marshmallow()
class CallSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = phoneCall
Since from
is a SQL keyword I can't directly use that as a column name. I tried setting it as
_from = db.Column("from", db.String)
But when I return a phoneCall.query.all()
I get the column name as _from
. Additionally, I'm using a dict with the key as from
to populate data into the table as well. How do get around this restricted keyword to accept input and also display the output of the query as
Input
call={'callid'='call34346346346',"duration":10 "from": "+1234", "to":"+1234"}
Expected output
[
{
"callerid": "call34346346346",
"duration":10
"from": "+1234",
"to":"+1234"
}
]
Actual output
[
{
"_from": "+1234",
"callerid": "call34346346346",
"duration":10
"to":"+1234"
}
]
Upvotes: 0
Views: 26