Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python app engine Model query for models in the same group

I have transactional Groups of entities of type db.Model that have a parent defined. I want to query the datastore to only return models that are in the same group. Currently I'm querying all objects of a 'Kind' then removing those that don't have the same root entity.

Is there a cleaner way to do this - I can't see one in the sdk.

for example:

from google.appengine.ext import db

class ParentObject(db.Model):
  ....


class ChildObject(db.Model):
  ....


parent1 = ParentObject()
parent2 = ParentObject()
child1 = ChildObject(parent=parent1)
child2 = ChildObject(parent=parent2)
child3 = ChildObject(parent=parent1)

I want to run a query that returns child1 and child3 because they have the same parent.

like image 475
probably at the beach Avatar asked May 29 '26 14:05

probably at the beach


1 Answers

I think this is what you are looking for.

get_chlids=ChildObject.all().ancestor(parent1)

To know more about modeling in appengine. You can have a look here

like image 174
Abdul Kader Avatar answered Jun 01 '26 04:06

Abdul Kader



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!