models - google datastore many to one references -



models - google datastore many to one references -

so have 2 model classes:

class dog(db.model): dogname = stringproperty() dogbreed = stringproperty() class cat(db.model): catname = stringproperty() catbreed = stringproperty()

and have 3rd model class hold pictures

class images(db.model): imagereference = referenceproperty(*animal*, collection_name = 'allimages') imageurl = stringproperty()

animal either dog or cat. not compile.

now question is: there way can set cat pictures in dog pictures? or need create more models this:

class dogimages(db.model): imagereference = referenceproperty(dog, collection_name = 'allimages') imageurl = stringproperty() class catimages(db.model): imagereference = referenceproperty(cat, collection_name = 'allimages') imageurl = stringproperty()

you utilize polymodel:

class animal(polymodel.polymodel): name = db.stringproperty() breed = db.stringproperty() class dog(animal): pass class cat(animal): pass

now can have referenceproperty references animals, , either dogs or cats permitted.

however, don't have properties specific each type of animal - why not have regular animal model, add together property indicating species is, , skip separate models entirely?

google-app-engine models google-datastore

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -