I had a problem and solved it; just want to know if there was another more elegant solution than the one I did. Please let me know if you know of a better option:
The issue: have a date-time column in my specific SQLITE3 table. wanted to create Year, Month, Day, Hour, Minute, Seconds and a few others like DATE and TIME. Not practical to clone the database table, so wanted a 'View' against it.
2) went to my project folder and brought up the MODELS.py, and cloned the table, and added a project_Vtablename table. (added the "V" in front of the table's name.
3) Went thru the "makemigrations" option, then the "migrate" option. when it successfully finished, I had both the project_tablename and project_Vtablename tables in the DB.
4) then to insert the extra columns, went to SQLITE3, developed and debugged a CREATE VIEW project_Vtablename statement, with all the additional columns added (Year, Month, etc). Of course I deleted the
project_Vtablename before creating it as a VIEW.
5) returned to the VIEWS.py program and copied the IMPORT statement to add the
project_Vtablename
, and cloned a function that is successfully reading the original - changed all instances of tablename to Vtablename. AND it WORKS.
Now, with the Year column, i can now much more easily use and understand my SQL filters when parsing a date-time column.
...so, is there a more elegant way to install a database VIEW than a method something like the above? If so, please SHARE IT so I and others can take advantage of it.