0

I have a main property that has a structured property. I have a property defined inside the structured property and it needs access to the parent property's values. The syntax I tried was self.key.parent().email, but that didn't do the trick. How can I do this?

class Individual(ndb.Expando):
    name = ndb.StringProperty()
    email = ndb.StringProperty()

    team_list = ndb.StructuredProperty(IndividualTeam, repeated=True)

class IndividualTeam(ndb.Model):
    team_key = ndb.KeyProperty()
    fundraise_amt = DecimalProperty()

    @property
    def donation_total(self):
        #This is my problem here
        return self.key.parent().email
Evan Plaice
  • 13,944
  • 6
  • 76
  • 94
rhefner1
  • 464
  • 4
  • 13

2 Answers2

2

Individual is not parent of IndividualTeam. Individual just include IndividualTeam only. You shold use Individual object access to email property.

najeira
  • 3,133
  • 2
  • 19
  • 21
0

you will always have the containing entity loaded, so make methods that need to know the properties of the containing entity methods of the that. Those methods can interrogate the entities in the structured property. It's hard to see the exact problem you are trying to solve because your donation_total doesn't seem like it's going to return an email.

johnlockwood
  • 247
  • 2
  • 7
  • For the sake of brevity, I excluded the code that calculates the donation totals. In short, it does a query using the email address to find donations and adds them up. As you can see in the model definition, there is a list of these structured properties, so it's not just one. So, I do need access to the parent property, but in my tests it doesn't seem to allow access. When I change the problem code to `return self.email`, I get: `AttributeError: 'IndividualTeam' object has no attribute 'email'` Based on what you said, it should allow me access but it doesn't. – rhefner1 Apr 09 '12 at 03:20