As you said, you can accomplish this using PolyModels, eg:
class Animal(db.polymodel.PolyModel):
...
class Mammal(Animal):
...
class Chimpanzee(Mammal):
...
class Monkey(Mammal):
...
and retrieve all Monkeys, Chimpanzees and other Mammals using:
animals = Mammal.all().fetch()
OR you can roll your own by using a ListProperty (or a StringListProperty),
eg:
class Animal(db.Model):
type = db.StringListProperty()
animal1 = Animal(type=['mammal'])
animal2 = Animal(type=['mammal','chimpanzee'])
animal3 = Animal(type=['mammal','monkey'])
db.put([animal1,animal2,animal3])
and retrieve all three using:
animals = Animal.all().filter('type = ','mammal').fetch()
I'm sure there are other solutions to this too.
Nick
On 19 July 2010 18:04, Bill Edwards <[email protected]> wrote:
> Hi!
>
> I've been recently trying to wrap my head around GAE's datatypes. Is
> there a model type in GAE that allows me to define subproperties? For
> example, I want to have a "category" property where some categories
> fall under others, and when i query for all entities within a
> supercategory, i get the subcategories also.
>
> For example:
> class Animals(db.Model):
> type = db.StringProperty()
>
> Animals(type='mammal')
> Animals(type='chimpanzee')
> Animals(type='monkey')
>
> When I query for all animals with type mammal, i want to return all 3
> of the above objects.
>
> I've read through the documentation, and the PolyModel datastore model
> has struck my eye as being potentially helpful. However, it doesn't
> seem to quite do the job.
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.