Search code examples
google-app-engineapp-engine-ndbdjangoappengine

How to Query a repeated property with a list object in google appengine ndb


I need to construct a logical query with a repeated property and can't get it to work. I have a list object with topics.

topics = [u'string1', u'string2', ...]

I have a query object:

videos = Video.query()
videos.count()
=> 19

topics is a repeated string property

class Video
  topics = ndb.StringProperty(repeated=True)

I want to return videos that have a topic string1 OR string2. I also don't know the length of the list object before or I could just construct the query the long way with logical operators.

I tried doing this like the documentation suggests

videos.filter( Video.topics.IN([topics]) )

but that throws the error that IN expected a string not a list object.

How do I do this?


Solution

  • Looks like topics is already a list. So you need to pass it without another list around it:

    videos.filter( Video.topics.IN(topics) )