BlobReferenceProperty 和 ReferenceProperty 模型设计

发布于 2024-11-09 19:48:07 字数 1696 浏览 4 评论 0原文

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

目前我有这样的设计:

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)

谢谢。

I have a design question is BlobReferenceProperty basically ReferenceProperty? Should I do prefetch (suggested by Nick http://blog.notdot.net/2010/01/ReferenceProperty-prefetching-in-App-Engine) like for ReferenceProperty?

Currently I have this design:

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)

Would this be better or worse? I have moved the blob to Entry instead.

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)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2024-11-16 19:48:07

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

谈到你的第二个问题,将 blob 移动到 Entry ,这取决于你的功能。

Blobreference property is similar to db.ReferenceProperty, except for the fact that the entity actually lies in the blobstore. So prefetching ReferenceProperty applies to BlobReferenceProperty as well. blobstore.py also includes get_value_for_datastore using which you can prefetch blob entities.

Coming to your second question,moving the blob to Entry , it depends on your functionality.

子栖 2024-11-16 19:48:07

如果您需要条目和图像之间的一对多关系,如果您希望每个条目都能够匹配许多图像,您可以使用类似于您的第一个模型的东西。我使用的关系有点像这样:

class Article(db.Model):      
    user=db.UserProperty(verbose_name="userid") 

class Image(db.Model):       
    reference=db.ReferenceProperty(Article,collection_name='matched_images')
    primary_image = blobstore.BlobReferenceProperty() 

You can use something like your first models if you are going to need a one-to-many relation between entry and image, if you want every entry to be able to match many images. I use a relationship somewhat like that:

class Article(db.Model):      
    user=db.UserProperty(verbose_name="userid") 

class Image(db.Model):       
    reference=db.ReferenceProperty(Article,collection_name='matched_images')
    primary_image = blobstore.BlobReferenceProperty() 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文