To be more exact what I want to do is this:
class FamilyMember(model.Model):
individual = model.KeyProperty()
relation = model.StringProperty(choices=utils.relations)
class Family(Node):
children = model.StructuredProperty(FamilyMember, repeated=True)
#What I am doing now:
isChild = False
for child in family.children:
if ind == child.individual:
isChild = True
#What I would like to do
isChild = ind in family.(some easy way to access the list of
children key properties)
Does my question make sense?
--
Michael Robellard
(216)288-2745
Play Railroad Empire: http://www.therailroadempire.com
You want a more compact way to spell [child.individual for child in
family.children] and you're somehow hoping that something like
family.children.individual would automagically return the above list.
Alas, in order to support that, family.children would have to return
some custom sequence class that knew about the structure of the
FamilyMember class. But there are several problems with that,
including what should have priority if FamilyMember were to have a
property named 'append' or 'sort' or any other list method.
So, the short answer is 'no', and I don't think it would be a good
idea to add this feature. But thanks for asking, you never know!
--Guido
--
--Guido van Rossum (python.org/~guido)
if i were to dream of an ideal relationship model it would probably be
something like:
class Family(Node):
class Family.FamilyMember(model.Model):
class Family.FamilyMember.ContactInfo(model.Model):
class Family.FamilyPets(model.Model):
etc
--Guido
i will consider your suggestions and respond in time
(I am new to python)
-Ptr
If I understand your SO question correctly this is a matter of understanding how Python works and how NDB represents repeated StructuredProperty, not a feature request.
--Guido van Rossum (sent from Android phone)