我正在使用烧瓶不安并尝试发帖以创建多对多关系的新记录
Categories = db.Table('categories',
db.Column(
'help_request_id', db.Integer, db.ForeignKey('help_request.id')),
db.Column('category_id', db.Unicode(20), db.ForeignKey('category.id')))
class Category(db.Model):
id = db.Column(db.Unicode(20), primary_key=True)
eng_name = db.Column(db.Unicode(50))
created_by_user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
created_by = db.relationship(User)
create_date = db.Column(db.DateTime, default=datetime.now)
imagePath = db.Column(db.Unicode(128))
# Required for administrative interface
def __unicode__(self):
return self.eng_name
class HelpRequest(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.Unicode(100))
categories = db.relationship('Category', secondary=categories,
backref=db.backref('helprequests', lazy='dynamic'))
我如何发布带有指定类别的帮助请求?感谢
亚历
答案 0 :(得分:-1)
最后解决了,只需使用正确的json格式,就像魔法一样。
{“title”:“testing3”,“categories”:[{“id”:“a”},{“id”:“b”}]}