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 urls.py:

python manage.py inspectdb\
  | grep "^class"\
  | sed "s/^class //g"\
  | cut -d"(" -f1\
  | xargs -I {} echo 'databrowse.site.register({})'\
  >> urls.py

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.

8 Responses

  1. actual test (not verified) Says:
    2009-04-16 17:03

    Amazing to see such a useful research work and its very good post. I will try this just after my 70-555 for Microsoft Office Groove 2007. Configuring about which I am confident to pass in first attempt because I have already pass 70-557 which is for Microsoft Forefront Client and Server, Configuring as well as your page concern I must say that you have done a great job I must return on your page to read you more.

  2. compost shredder (not verified) Says:
    2009-04-15 10:00

    Amazing to see such a useful research work

  3. John Smith (not verified) Says:
    2009-04-14 09:08

    Thx so much.

  4. John Smith (not verified) Says:
    2009-04-14 09:07

    python manage.py inspectdb |
    grep "^class" |
    sed "s/^class //g" |
    cut -d"(" -f1 |
    xargs -I {} echo 'databrowse.site.register({})'\
    >> urls.py
    flash game

  5. yaoo (not verified) Says:
    2009-04-06 17:47

    this is good post

  6. TestKing (not verified) Says:
    2009-02-04 12:40

    Really impressive work and clear research on topic you are working really well with clear way of explaining things. i will comeback again as I get some time form my 70-290 exams for managing and maintaining a microsoft windows server 2003 environment. Which will be really help ful for me in upcoming certification of 70-291 for MCSE 2003 security managing and maintaining a microsoft windows server 2003. I will return again on your page as you have done a great job. Thanks for all.

  7. Anonymous (not verified) Says:
    2008-10-04 16:08

    It's a bit OT but you can write that shell script a bit better:

    python manage.py inspectdb |
    grep "^class" |
    sed "s/^class //g" |
    cut -d"(" -f1 |
    xargs -I {} echo 'databrowse.site.register({})'\
    >> urls.py

    E.g., why use both a \ and a | when the | alone suffices?
    And of course you can go better: the following will
    combine the sed and grep steps:

    sed -n "/^class /s///gp" |

    With more work you could combine the grep, sed and cut with a single sed or (preferably) awk.

  8. Smith (not verified) Says:
    2009-05-08 18:10

    I like being here. its really interesting.keep it up