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()

More like this

  1. inspectdb fixer by kriberg 4 years ago
  2. Extended cacheable callables and properties by gsakkis 2 years, 11 months ago
  3. DisplayModelForm by koenb 5 years ago
  4. A small script to rearranging the models generated from inspectdb command by m_tayseer 4 years, 6 months ago
  5. FlatPageOverrideMiddleware by David 4 years, 5 months ago

Comments

(Forgotten your password?)