2011-04-11 52 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