Home > appengine > appengine – SELECT using OR clause – alternative

appengine – SELECT using OR clause – alternative

Problem:
Appengine does not support SELECT using an OR clause. There are a number of options out there and this is one of them. The Kind I am using this on will not have alot of data and I am hoping (fingers crossed) that it will not cause a performance issue later on.

Solution:
Filter, StringListProperty.

from googleappengine.ext import db

class Post(db.Model):
    author = db.StringProperty()
    category = db.StringListProperty()

post = Post(author="Sam", category=['bash', 'emacs','lisp'])
post.save()
post = Post(author="Peter", category=['bash', 'appengine'])
post.save()
post = Post(author="Ken", category=['mail', 'django','irc', 'sql'])
post.save()

results = Post.all().filter('category = ', 'bash')

for item in results:
    print item.author, item.category

Results
You would then get the following two items.

Sam [u'bash', u'emacs', u'lisp']
Peter [u'bash', u'appengine']

Source:
http://stackoverflow.com/questions/3455090/querying-for-a-value-existing-in-a-models-list-property-in-appengine/7430151#7430151

Advertisements
Categories: appengine
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: