Porting a Django app to App Engine

Saturday, 8th November 2008

After recently developing something in app engine and, generally liking it, I thought I would port over a new paster which quickly stole all the RAM on my slice - because, how hard could it be?

Now, first of all - pretty much everyone knows that (at least running app-engine-patch) Django’s models go out the window to use Google’s scaling monster, BigTable. This in turn screws up some of the internal things such as the form field ModelChoiceField (which I created an incredibly ugly work around for, which itself should be a post) but also removes the nifty shortcuts and you’ll have to rewrite a lot of code.

At least I can pretend that they are Django models

I use the pk shortcut a lot in this specific app, which is just the default auto incremental id field which MySQL uses - but in BigTable this shortcut doesn’t exist, so I just created this simple pk() function in my model to replicate it:

def pk(self):
    return self.key().id()

I’m not sure if BigTable keeps the ID field on rows if you assign your own key, but I went with the default auto generating key.

This lets me keep my pk shortcut in my templates but you’ll have to use pk() in python code.

I’ve also added an alias for the Django save() function in my models:

def save(self):
    return self.put()

This makes save() work exactly like put() in my views, which in my opinion makes everything a bit more clear.

Have you ported a Django app to App Engine, if so, what small fixes did it take to get it working?

2 comments

  1. 's gravatar 3rd September 2009

    theRealKiyosaki

    It’s just a wonderful response

  2. 's gravatar 18th November 2009

    qwrt_

    Dear Author luddep.se ! Very good idea

Write comment

Optional

No HTML is allowed, please use Markdown for text formatting.

Emails are never published, but are used to spice up your comment through Gravatar.