Question

Here are my many-to-many relationship models:

class ModelA(ndb.Model):
    name = ndb.StringProperty(required=true)
    model_b = ndb.KeyProperty(kind=ModelB,repeated=True)


class ModelB(ndb.Model):
    name = ndb.StringProperty(required=true)
    model_a = ndb.KeyProperty(kind=ModelA,repeated=True)

My question is, how do I add/update/delete a single (or many) KeyProperty from let's say model_b?

Was it helpful?

Solution

I managed to do it like this:

pos = ModelA.model_b.index(ndb.Key('ModelB',213)) # Get position from list
ModelA.model_b.pop(pos) # Remove from list
ModelA.put() # Update
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top