My question is about how to use post to add more than one many to many relationship datas
I'm using flask, flask-SQLAlchemy, flask-restless and angularjs, json
I have some tables like this
class Page(db.Model):
id = db.Column(db.Integer, primary_key=True)
page_name = db.Column(db.String(10))
class Tag(db.Model):
id = db.Column(db.Integer, primary_key=True)
tag_name = db.Column(db.String(10))
class PageTags(db.Model):
page_id = db.Column(db.Integer, db.ForeignKey('page.id'), primary_key=True)
tag_id = db.Column(db.Integer, db.ForeignKey('tag.id'), primary_key=True)
info = db.Column(db.Text)
tag = db.relationship('Tag', backref='tag')
page = db.relationship('Page', backref='pagetags')
I want to post a data like this
{
"id": 1,
"page_name": "p1",
"pagetags": [
{
"info": "pt1",
"page_id": 1,
"tag_id": 1
},
{
"info": "pt2",
"page_id": 1,
"tag_id": 2
}
]
}
and I hope to add this to database which will create three things:
one page, and two pagetags.
Can I do this with restless? And How to do?
appreciate it in advance.
From here:
apimanager.create_api( Page, include_columns = [
'id', 'page_name', 'pagetags.info', 'pagetags.page_id', 'pagetags.tag_id'
] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With