django-dynamic-models icon indicating copy to clipboard operation
django-dynamic-models copied to clipboard

Create dynamic model for existing table by inspecting the database?

Open ecederstrand opened this issue 3 years ago • 0 comments

I have a PostgreSQL database that is not managed by Django. Tables are continuously added to it. You could think of it as a data lake or data warehouse.

I'd like to use the Django ORM to query these tables, but tables are inserted often enough that manage.py inspectdb to generate on-disk code is not practical. Instead, I'm thinking to hook into the internals of the Django inspection code to get the definition of a specific table (providing just the table name), and then use this package to dynamically create a model definition, allowing me to use the ORM on this model.

Has anyone done this before? Do you have any pointers on where to start, or things to note?

Also, if I don't want to store the dynamic models in the database, can I use ModelSchema and FieldSchema without saving the instances to the database?

ecederstrand avatar Nov 14 '22 10:11 ecederstrand