You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not documented because nobody has confirmed it's stable and I am personally not using these features right now so I can't guarantee their stability. There is also some missing functionality, such as the ability to change the backing query on a view.
The basics:
frompsqlextra.modelsimportPostgresModel, PostgresViewModelclassSomeModel(PostgresModel):
name=models.TextField()
classMyView(PostgresViewModel):
classViewMeta:
# alternatively, you can specify raw SQL here:# query = ("SELECT ...", (param1, param2))query=SomeOtherModel.objects.filter(name="test")
# all fields returned by `query` must be specified as fieldsname=models.TextField()
frompsqlextra.modelsimportPostgresMaterializedViewModelclassMyMaterializedView(PostgresMaterializedViewModel):
classViewMeta:
query=SomeOtherModel.objects.filter(name="test")
# all fields returned by `query` must be specified as fields name=models.TextField()
MyMaterializedView.refresh(concurrently=True)
Use python manage.py pgmakemigrations to automatically create the views in your database. Changing the query is unfortunately not supported in the migrations right now, you'll have to do that manually.
Thanks @Photonios. This is helpful. I've removed it from my project for now. Once I have some breathing room (hopefully in a few months), I'd be happy to add it back in and help with testing, documentation, and migrations at that point.
Would love to see an example for
PostgresViewModel
.I've tried reading through the code to figure out how to use it, but am unclear on the implementation.
E.g., something like what they have in https://github.com/xelixdev/django-pgviews would be great
The text was updated successfully, but these errors were encountered: