Fork me on GitHub

Using Django's Databrowse With Inspectdb

The Django databrowse application is an interesting piece of software that I've wanted to try out ever since its creator, Adrian Holovaty, demoed it in Vancouver last year. Its purpose is to allow you to navigate data, using a web interface, looking for trends and other interesting aspects.

In conjunction with Django's inspectdb command, which creates Django model definitions by inspecting the schema of an existing database, you can potentially use databrowse on data from any application.

One annoyance with databrowse is having to register each model with it. I created a shell concoction to generate register statements for each model created by inspectdb and append them to

python inspectdb\
  | grep "^class"\
  | sed "s/^class //g"\
  | cut -d"(" -f1\
  | xargs -I {} echo '{})'\

I attempted to use databrowse on a database full of Drupal data, however, and ran into a current limitation of Django. Django models can't employ primary keys composed of multiple columns. Drupal's database schema uses this kind of primary key repeatedly.