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. Save a model using an arbitrary db connection by weswinham 2 years, 8 months ago
  2. Custom 'save' method, automate creating pdf file from entry. by I159 8 months ago
  3. PowerDNS models by diverman 2 years, 12 months ago
  4. Models with database views by diverman 2 years, 11 months ago
  5. Unittest: Compare max_size with column size of database by guettli 3 years, 9 months ago

Comments

(Forgotten your password?)