Readline tab completion using Django models

December 28, 2009

Seen on Planet Debian, a totally sweet hack involving using readline-style tab completion based on some random crap you have in your Django database.

import readline

from mymodels import MyModel

completer = QuerySetCompleter(MyModel.objects.all(), 'name')
readline.set_completer(completer)

readline.parse_and_bind("tab: complete")
readline.set_completer_delims('')

while 1:
    print repr(raw_input(">>> "))

Comments are closed.