I have an application that needs to generate its models at runtime.
Take a look at the source code for the inspectdb management inspectdb . inspectdb "Introspectively scans the database tables in the database pointed to by the NAME parameter and displays the Django model module (models.py file) to standard output."
How can I create classes at runtime in python?
One way to do this is to use the functions provided by the new module (this module has been deprecated in favor of types since version 2.6).
Should I create a json view and save it in the database and then not initialize it to a python object?
That doesn't seem like a good idea to me.
PS: Everyone said that you should really rethink the prerequisites for creating classes at runtime. This is quite extreme for a web application. Just my 2c.
source share