2014-09-05 79 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