Quick and dirty way to make dynamically available all tables of a database as models

1
2
3
4
5
6
7
#Put this in yourproject/yourtestapp/models.py

from django.core.management import inspectdb

code = "\n".join(inspectdb())
code = code.replace("    class Meta:", "    class Admin: pass\n    class Meta:")
exec code in globals()

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.