如何为一个对象建模许多blob? [英] How to model many blobs for an object?

查看:169
本文介绍了如何为一个对象建模许多blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本对象和blob之间启用类似于一对多关系的东西,以便文本对象(文章或类似文件)具有许多图像和/或视频。有两种方法可以看到如何在第一种方法中使用blob列表作为实例变量。

I want to enable something like a one-to-many relation between a text object and blobs so that a text object (an "article" or likewise) has many images and/or videos. There are two ways I see how to do this where the first is using a list of blobs as instance variable. Will it work?

class A(search.SearchableModel):
  blobs = db.ListProperty(blobstore.BlobReferenceProperty())

优点:只需一个班级。易于读取和设置数据。
缺点:缺少额外的blob信息,例如如果我想用描述性词语来标记blob,我仍然需要两个类:

Advantages: Just one class. Readable and easy to get and set data. Disadvantages: Lacks extra info for blobs e.g. if I want to tag a blob with descriptive words I still need two classes instead:

class A(search.SearchableModel):
...
class B(db.Model):
  reference=db.ReferenceProperty(A,collection_name='matched_blobs',verbose_name="Title")
  blob = blobstore.BlobReferenceProperty()

后面的例子有一个缺点,因为它需要引用属性并引入2个类,可以像第一个例子一样只用A类来解决。后面的解决方案的优点是,它明确记录,而blobreferenceproperties的列表属性不是,我已经实现了后来的解决方案,现在我正在考虑使用blob列表而不是引用集合。它是否重要,或者两者都工作得相当好?你可以推荐哪种方式选择,如果有这些或其他吗?

The later example has a disadvantage since it requires a referenceproperty and introduces 2 classes where the problem could be solved with just class A as in the first example. The advantage of the later solution is that it's clearly documented while a listproperty of blobreferenceproperties isn't and the later solution I already have implemented and now I'm thinking about using a list of blobs instead of a referenced collection. Does it matter or will both work rather equally well? Can you recommend which way to choose, if any of these or another?

谢谢

Thanks

推荐答案

App Engine在他们的文档中实际上有一篇文章: http:/ /code.google.com/appengine/articles/modeling.html

App Engine actually has an article on this in their documentation: http://code.google.com/appengine/articles/modeling.html

这篇关于如何为一个对象建模许多blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆