user1152327
user1152327

Reputation: 149

App engine datastore - searching a list of entities

I have pulled a list of entities from my datastore in app engine. Each entity in the list has a "name" attribute. Is there a quick way to search the list of entities for a specific name?

As opposed to iterating through each one and checking the name attribute

Thanks!

Upvotes: 0

Views: 194

Answers (1)

Paul Collingwood
Paul Collingwood

Reputation: 9116

You can pull out the entity you are looking for directly if you have an attribute you can match against

q = Person.all()
q.filter("name =", target_last_name)
result = q.get()

But as far as I know, you have to iterate around the result list if you are not querying against a specific attribute.

This link talks about efficent ways to do that however:

Searching a list of objects in Python

E.G.

     [x for x in myList if x.n == 30]

Upvotes: 1

Related Questions