2013-03-29 46 views
0

我讀過一些有關建模的谷歌文檔(順便說一句,我是一個新手與python和GAE/webapp2)。這樣做與關係會更容易,但我試圖學習谷歌應用程序引擎,與數據存儲和/或ndb。App引擎和模型與蟒蛇的關係

試圖做的事:我有一個有幾個區域的家,每個區域都有一組傳感器(光源,溼度,tmp),它們會讀取數據並將它們發送到服務器。

事情是這樣的:

Class User(db.Model): 
user = db.UserProperty() 
usertype = db.StringProperty()(aka mom/father/child) 

class Home(db.Model): 
zone = db.IntegerProperty() #Zones in home unique int 
zonename = db.StringProperty() # optional name for the zone 

class Zone(db. Model): 
sensortype = db. key or name? # I'd like to model moisture/tmp/light sensors that will be hereSensors in zone (from class sensors ?) 
SensorID = #Ideally a key for that sensor in the zone ? 
DateCreated = db.DateProperty() 

class Sensors(db.Model): # this will get the actual readings when they come in 
Sensortype (moisture, tmp, light) 
timeReading = db.DateProperty() 
Reading = db.FloatProperty() 

稍後我將要閱讀所有的溫度讀數(從所有區域或單個區域),許多傳感器,或單獨的傳感器。能夠按日期/時間排序。我會將這些讀數與天氣報告進行比較。

我很難搞清楚我是否應該使用結構化對象,父母/祖先的鍵或ReferenceProperty。

從哪裏開始?我對這個最好的模型感到茫然。

在此先感謝您的幫助。

+0

可能重複的[在谷歌應用程序引擎使用祖先或參考屬性?](http://stackoverflow.com/questions/12123511/using-ancestors-or-reference-properties -in-google-app-engine) – dragonx

+0

在您的具體示例中,我將製作區域的首頁和祖先,區域和傳感器的祖先,並且它們之間完全沒有任何引用屬性。傳感器固定在空間,區域和家庭區域。話雖如此,調整你的模型,以適應你的訪問模式。只是我的2C ;-) –

+0

感謝您的答覆。我一直在想,但想要確認。使用StructuredProperty作爲傳感器/區域還是不使用?我在https://developers.google.com/appengine/docs/python/ndb/properties#computed – prussiap

回答