Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create dynamic model for existing table by inspecting the database? #61

Open
ecederstrand opened this issue Nov 14, 2022 · 0 comments
Open

Comments

@ecederstrand
Copy link

ecederstrand commented Nov 14, 2022

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 ecederstrand changed the title Create dynamic model by inspecting the database? Create dynamic model for existing table by inspecting the database? Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant