So I have been using Django's ORM for everything; however, I have gotten to a part of this application where I don't think it makes sense. That is unless, models can be dynamically generated and dropped into models.py so I don't have to update it every year.
The company this application is for aggregates data from various industries. There is no overlap between them. Furthermore, the data collected from each industry can vary from year-to-year. Thus tables are broken up like:
Industry_A_15
Industry_A_16
Industry_A_17
Industry_B_15
Industry_B_16
Industry_B_17
I don't see how the ORM could work unless I added them to models.py
every year (there are over a hundred columns for each). The most efficient way, I can think of, for doing it would be to do something like ./manage.py inspectdb > models.py
, but that tends to not work on tables with constraints.
So would this be a good case to write in raw SQL?
It sounds like I'd want to avoid the model layer altogether really:
https://docs.djangoproject.com/en/2.0/topics/db/sql/#executing-custom-sql-directly
Then I could dynamically refer to the tables and really not have to touch it in the future. Also, the queries would be pretty basic SELECT
such that I would think it should be portable between major databases. (The tables are created from a CSV upload so nothing is really being done manually to create them).