2014-09-05 37 views
0

希望你能帮助我!自我参照关系消失在烧瓶管理员

我在SQLAlchemy的关系如下:

class Location(db.Model, DateModified, Sluggable): 
    __tablename__ = 'location' 
    __sluggable__ = { 
     'populate_from': 'title', 
     'always_update': True 
    }  
    id = db.Column(db.Integer, primary_key=True) 

    title = db.Column(db.String(80)) 

    ... 

    parent_location_id = db.Column(db.Integer, db.ForeignKey('location.id'), index=True) 
    parent_location = db.relationship(lambda: Location, remote_side=id, backref='child_locations') 

我为如何调试间歇瓶管理员或SQLAlchemy的是失去了parent_location_id在保存父位置其实真的不确定。

这消失的行为似乎是相当随机的。

任何人有任何线索,我如何调试这将帮助极大!

谢谢。

+0

有一棵树的SQLAlchemy示例 - 它也发生在那里吗? – Joes 2014-09-14 07:48:02

回答

0

乔斯,感谢提醒我回答这个问题。

这只是我在我的模型中有一个backref被隐藏在窗体上。因此,提交的数据是空的清除关系。

故事的道德:不要在您的管理表单中隐藏回溯。

+0

尊敬的pip,你知道有没有什么方法可以显示字段,将其设置为只读,并且在提交表单时,还将其值呈现给服务器端,以便它不会从数据库中删除? – 2015-06-18 05:11:45

+0

http://stackoverflow.com/questions/14874846/readonly-text-field-in-flask-admin-modelview/23959450#23959450 – pip 2015-06-18 09:36:20