2011-04-11 47 views
1

我正在設計一個張貼系統的模型,其中一個條目包含帶有或不帶註釋的圖像。用戶可以回覆它作爲評論或圖像條目。App引擎上的Polymodel建議

由於ImageEntry可以有更多的屬性,我用Polymodel提出了這個設計。不知道這是否是這樣做的最佳方式。存儲方面,CommentEntry是否比ImageEntry少?

任何建議將是偉大的。

class Entry(polymodel.PolyModel): 
    comment = db.TextProperty() 
    reply_to = db.SelfReferenceProperty() # reference to the entry 
    created_at = properties.DateTimeProperty(auto_now_add=True) 
    updated_at = properties.DateTimeProperty(auto_now=True) 

class CommentEntry(Entry): 
    created_by = db.ReferenceProperty(User, collection_name='comment_entries') 

class ImageEntry(Entry): 
    created_by = db.ReferenceProperty(User, collection_name='image_entries') 
    image_url = db.LinkProperty(indexed=False) 
    slug  = db.StringProperty(indexed=False) 

回答

1

這種模式將做工精細,是的,一個CommentEntry會比如果ImageEntry有一個圖像URL和/或蛞蝓同一用戶的ImageEntry小。

然而,通過將 的created_by,image_url和slug放入Entry並將CommentEntry和ImageEntry完全清除 ,我會做得更簡單。因爲 the app engine datastore is schemaless, 和properties are optional by default, 只有在您爲圖像條目填充 時,您纔會支付image_url和slug屬性的費用。

+0

實際上我還有幾個ImageEntry的屬性,但只有Entry才更簡單。謝謝你清理那個。 – Dave 2011-04-11 21:15:31