BlobReferenceProperty and ReferenceProperty model design
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.Stri开发者_JAVA百科ngProperty(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.
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.
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()
精彩评论