Handle SQLite substr syntax

Addresses https://github.com/torchbox/wagtail/issues/11
Merge branch 'master' of github.com:torchbox/wagtail