我有一个设计问题,是BlobReferenceProperty基本上是ReferenceProperty吗?我是否应该像ReferenceProperty那样预取(由Nick http://blog.notdot.net/2010/01/ReferenceProperty-prefetching-in-App-Engine建议)?

目前我有这个设计:

class Entry(db.Model):
  creator     = db.ReferenceProperty(User, required=True, collection_name='entries')
  created_at  = db.DateTimeProperty(auto_now_add=True)

  # image
  image_id    = db.StringProperty() # key_name for Image
  image_url   = db.LinkProperty(indexed=False)
  width       = db.IntegerProperty(default=0, indexed=False)
  height      = db.IntegerProperty(default=0, indexed=False)


class Image(db.Model):
  created_at    = properties.DateTimeProperty(auto_now_add=True)
  blob          = blobstore.BlobReferenceProperty(required=True)
  filename      = db.StringProperty(indexed=False)
  published     = db.BooleanProperty(default=False, indexed=True)
  width         = db.IntegerProperty(default=0, indexed=False)
  height        = db.IntegerProperty(default=0, indexed=False)


这是好是坏?我已将Blob移至Entry。

class Entry(db.Model):
  creator     = db.ReferenceProperty(User, required=True, collection_name='entries')
  created_at  = db.DateTimeProperty(auto_now_add=True)

  # image
  image_blob  = blobstore.BlobReferenceProperty(required=False)
  filename    = db.StringProperty(indexed=False)
  image_id    = db.StringProperty()
  image_url   = db.LinkProperty(indexed=False)
  width       = db.IntegerProperty(default=0, indexed=False)
  height      = db.IntegerProperty(default=0, indexed=False)


谢谢。

最佳答案

Blobreference属性与db.ReferenceProperty相似,但该实体实际上位于blobstore中。因此,预取ReferenceProperty也适用于BlobReferenceProperty。 blobstore.py还包括get_value_for_datastore,您可以使用它预取blob实体。

关于第二个问题,将Blob移至Entry,这取决于您的功能。

10-06 08:37