Here's a little something that I've hacked up, which I'm posting here
to see whether anyone can take it any further.

After seeing Jacob use Django to inspect his iPhone's databases I
wondered whether some sort of automatic database browser could be
scripted up. Here's the simple example I got working:

1. First make a new project (db_test) and app (my_big_fat_fake_app).
2. Configure the settings file to point at the database you'd like to inspect.
3. Add admin and my_big_fat_fake_app to the INSTALLED_APPS.
4. Create an inspect.py file with the following in it:
================
import sys, os

from django.core.management.commands import inspectdb, runserver, syncdb
from django.core.management import setup_environ

import settings
setup_environ(settings)

c = inspectdb.Command()
s = c.handle_inspection()

new_lines = []
for line in s:
    if "class Meta" in line:
        new_lines.append("    class Admin:")
        new_lines.append("        pass")
        new_lines.append("    class Meta:")
        new_lines.append("        app_label='my_big_fat_fake_app'")
    else:
        new_lines.append(line)
lines = "\n".join(new_lines)
a = compile(lines, "<string>", "exec")
exec(a)

s = syncdb.Command()
s.execute()

r = runserver.Command()
r.execute()
================
5. Run the file (python inspect.py)
6. This should create all of the Django tables in your database,
prompt you to create a superuser and then launch the development
server. You should then be able to log in and browse and edit the
database.

Problems:
1. Running it twice will add all of the Django tables to the admin index.

Future features:
These are the things I'd like to implement but I'm getting stuck on:
1. Prompt the user for the database string (I'm getting stuck tweaking
the settings module).
2. Auto-create a superuser (use a default or take it from the command line).
3. Eliminate the need to create a project and app.
I've tried dynamically creating urls and settings and can get the
admin interface up, but no models are shown (this seems to be because
the fake app I created isn't recognised by the admin). I've been using
the 'new' module but quickly started to bump up against my lack of
python-internals knowledge.
4. (This is the magic one) Use the multi-db branch to create the
Django and admin tables in a sqlite://:memory: database.
If this was possible then you could point the script at any database,
browse and edit, and leave it otherwise untouched. Which I think would
be pretty sweet.

I've posted this to developers as I think it requires some in depth
knowledge of how Django does its job. Apologies if it's a bit off
topic.

Hope this inspires someone.

Regards,

Felix

P.S. Apologies for the pun in the subject line: it's the best Django
joke I could come up with (thank you http://thesaurus.reference.com/)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to