-1

我正在使用烧瓶不安分并尝试发帖为多对多关系创建新记录

   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'))

我如何发布带有指定类别的帮助请求?谢谢

亚历克斯

4

1 回答 1

-1

终于解决了,只要使用正确的 json 格式,它就像魔术一样工作。

{"title":"testing3","categories": [ {"id": "a"}, {"id":"b"}]}

于 2015-03-21T08:59:34.630 回答