Saturday, May 2, 2009

Never pass an extended db.Model to Django

Despite it will work locally, Django will not recognize a property added to a db.Model.

Example:

class Example(db.Model)
username = db.StringProperty()
password = db.StringProperty()

examples = Example().all().fetch(10)

for example in examples:
example.address = 'hello'

template_values = {
'examples': example
}

Django won't see example.address only with the local Appengine SDK environment! It might work with the db.Expando mode but quite confusing since the added property (address) will be unreachable only after the application is uploaded to the GAE servers.

Possible solution:
class Example(db.Model)
username = db.StringProperty()
password = db.StringProperty()

examples = Example().all().fetch(10)

elist = []
for example in examples:
eitem = {
'example': example,
'example_address': 'hello'
}
elist.append(eitem)

template_values = {
'examples': elist
}
Thanks for Eoghan for finding a solution.

Friday, May 1, 2009

Building an App Engine Google Query - Terror of the missing white space

Lesson learned:

Always use white space between query filters and the equality signs otherwise the equal sign will be interpreted as part of the index key.

Example:

Wrong:


cattoplist = dbmodels.DailyStats.all().filter("kc_date=", today).filter("kc_category=", cat.cat_id).order("-visitor_new").fetch(catnum, catoffset)

Good:


cattoplist = dbmodels.DailyStats.all().filter("kc_date =", today).filter("kc_category =", cat.cat_id).order("-visitor_new").fetch(catnum, catoffset)



Introduction

This blog is dedicated to follow my adventures in the cloud. I'm working on high performance, distributed, scalable systems since many years and recently I've started to test Google's infrastructure, the Google Application Engine. I'll log every useful thoughts and experiences to avoid myself - and hopefully other developers as well - to fall into the same trap.