John Borwick’s blog

Neat stuff John likes.

October 30th, 2008
October 27th, 2008

appengine_django, BaseModel, and SearchableModel

I have been learning how to write Django code for Google App Engine.  (Django is a Python framework, which Google chose to incorporate into Google App Engine.  Django is cool.)

Google has a few Django customizations, which they package in “google-app-engine-django“.  For example, the base class that your Django models use is supposed to change to BaseModel, a django helper front-end to “db.Model”, a Google Bigtable database model.

Today I wanted to implement search for one of my Django models.  Google has an article about setting up search using SearchableQuery, and some discussion posts about how to use ext.search and search.searchableModel, but nothing about how to use search.searchableModel with BaseModel.

The solution (which I probably shouldn’t be happy with):

  1. Go to $ROOT/appengine_django
  2. Edit models.py
  3. Put “from google.appengine.ext import search” towards the top
  4. Copy the “class BaseModel” class
  5. Paste it in below itself, and change the top line of what you pasted to “class SearchableModel( search.SearchableModel ):”
  6. Have your Django models inherit from SearchableModel

This allows you to say YourModel.all().search( ‘x’ ).  w00t.

October 26th, 2008
October 25th, 2008

Messing with Django and Google App Engine

I’m trying to figure out how to make Django 0.96 work with Google App Engine.  Here are the resources I’ve found so far:

I’ve found a few issues so far, that weren’t explicitly mentioned in these notes…

  • All models should use BaseModel from the django helper (this is stated)
  • All Python module names are relative to the root directory (e.g. myapp.views) rather than relative to the parent of the root directory (e.g. myproject.app.views).
  • Generic views do not work.  You have to re-implement the views yourself.
  • Once using the app engine helper, do not use dev_appserver.py.  Using “python manage.py shell” will consult a separate content store and you will be confused.  Instead use “python manage.py runserver”, the Django-esque way of doing things.
  • Restart the development server after using “python manage.py shell”.  I’m imagining there’s a caching issue.
  • All sorts of basic Django model syntax is broken.  YourClass.get( pk=1 ) becomes YourClass.get_by_id( 1 ), for example.  YourObject.choice_set.create does not work either.
  • The object ID is stored at object.key().id()

I’m sure there’s a bunch more to learn, but I’ve finally gotten the Django tutorial example to work.

October 17th, 2008
October 13th, 2008
October 9th, 2008
October 6th, 2008
October 3rd, 2008
October 2nd, 2008
|