> Are there any sensible ways to do this with Django? Ideally with migrations to create and update the views.
There are apps to integrate PG views as django models, however is kind of trivial to do it yourself.
1. Create a migration that runs the SQL to create the view like ```create VIEW active_users AS SELECT rest of view ... `
2. Create a model mapping all the fields you want to use, add the Meta.table_name with the name of the view, and Meta.managed=False to avoid adding this to your migrations in the future.
Use it as any other normal Model.
Just that
About the updates with migrations I think if you already are thinking on using VIEWS, you could just create migrations that drop and recreate it when you needed. Is what I do, and is very little work for that.
If you use a migration tool that works at the database level rather than the model level, the the migration handling of views will be automatically supported.
Last time I tried to do model a database view in Django it was painful, but support may have improved since.
But worst case you can drop down to a vanilla query.
There are apps to integrate PG views as django models, however is kind of trivial to do it yourself.
1. Create a migration that runs the SQL to create the view like ```create VIEW active_users AS SELECT rest of view ... `
2. Create a model mapping all the fields you want to use, add the Meta.table_name with the name of the view, and Meta.managed=False to avoid adding this to your migrations in the future.
Use it as any other normal Model.
Just that
About the updates with migrations I think if you already are thinking on using VIEWS, you could just create migrations that drop and recreate it when you needed. Is what I do, and is very little work for that.