2

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.

willi
  • 6,559
  • 4
  • 30
  • 27

2 Answers2

1

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.

Abdul Kader
  • 5,781
  • 4
  • 22
  • 40
  • That's not technically true. The BlobKey stored on the BlobReferenceProperty actually points to a BlobInfo Entity not directly to the blobstore. BlobInfo is just a regular datastore entity that holds information about your Blob and provides an API to fetch it. Answer still stands tho, can can still prefetch the BlobKey which can be useful to skip the BlobInfo step when you don't need it. – Chris Farmiloe May 24 '11 at 13:34
0

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() 
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424