1
binux 2013-04-01 15:43:24 +08:00
category_id是一个int,你传一个对象给它干嘛?
|
2
scarlex OP @binux
我看教程好像也是传值的..? 教程: u = models.User(nickname='susan', email='[email protected]') p = models.Post(body='my first post!', timestamp=datetime.datetime.utcnow(), author=u) 教程的表示这样的: class User(db.Model): --id = db.Column(db.Integer, primary_key = True) --nickname = db.Column(db.String(64), unique = True) --email = db.Column(db.String(120), unique = True) --posts = db.relationship('Post', backref = 'author', lazy = 'dynamic') class Post(db.Model): --id = db.Column(db.Integer, primary_key = True) --body = db.Column(db.String(140)) --timestamp = db.Column(db.DateTime) --user_id = db.Column(db.Integer, db.ForeignKey('user.id')) |
3
Catstyle 2013-04-01 16:19:36 +08:00 1
@scarlex
----posts = db.relationship('Post', backref="posts", lazy="dynamic") 你这里错了,这个表达的是你通过Post的实例访问‘backref’能反射到自己 意思就是说p.backref == c 所以你这里应该是 ----posts = db.relationship('Post', backref="category", lazy="dynamic") p=Post(title='test', content='ccc', timestamp=datetime.utcnow(), category=c) 然后p.category就是这个c实例 |