Archive for the ‘appengine’ Category

appengine – SELECT * From my_model WHERE category LIKE ‘news%’

December 13, 2011 Leave a comment

I needed to use a LIKE query in appengine.

Got some great answers from google search.

The solution I went with is here.


Where in sql you usually would query:

"SELECT * FROM thought WHERE user LIKE gra%"

We now have to use:

"SELECT * FROM thought WHERE user >= 'gra' AND user < :1", u'gra' + u'\ufffd'"

Imagine the table as being sorted alphabetically, user >= ‘gra’ would include any user-names that come after, or equal, ‘G’, then ‘R’, then ‘A’ in the alphabet. The next filter is a less-than inequality, so it’s going to filter out any values that are greater than the specified term, which we set as u’gra’ + u’\ufffd’. The unicode character and ‘\ufffd’ code specify that the result must include the first three character, ‘gra’ (formatted as unicode in order to concatenate with “u’\ufff'”), as well as any other unicode characters following that. This will limit the query enough to return a value such as ‘graeme’, if the search term is ‘grae’, but will not return ‘graham’, or, say, ‘tagrae’.

1. This works pretty well as the amount of data that I have will be “relatively small”.
2. The data saved in category field is in lowercase, without spaces or punctuation for easier search. Above solution is case sensitive.

Categories: appengine Tags:

Appengine – Appstats (python)

September 15, 2011 Leave a comment

Setting up Appstats for python and djangoappengine.

Assuming you have your djangoappengine setup as explained here.
Now following the instructions from

1. Add this to


    # ...

2. Add this to app.yaml

- appstats: on

That’s it. Now start your server is running

python2.5 runserver

Point your browser to
You should see something like

Now add some data by visiting some pages eg (Do this in a different tab then refresh.) You should have some stats now.

That’s it. Very simple and straight forward instructions from the docs.

Categories: appengine, django Tags: ,

Google I/O: Building Scalable, Complex Apps on App Engine

September 15, 2011 Leave a comment

appengine – SELECT using OR clause – alternative

September 15, 2011 Leave a comment

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.

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 = Post(author="Peter", category=['bash', 'appengine'])
post = Post(author="Ken", category=['mail', 'django','irc', 'sql'])

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

for item in results:
    print, item.category

You would then get the following two items.

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


Categories: appengine