问题
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())
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()
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
回答1:
App Engine actually has an article on this in their documentation: http://code.google.com/appengine/articles/modeling.html
来源:https://stackoverflow.com/questions/7204365/how-to-model-many-blobs-for-an-object