django_view_models
Designed for Postgres. May or may not work with other databases.
Installation/Usage
pip install django_view_models- add
django_view_modelstoINSTALLED_APPS - define view models (see below)
python manage.py sync_view_models(run after every view definition change)
Defining View Models
You must define the fields on your model, and either define VIEW_DEFINITION or view_query on your model.
Note that just like regular models, django will add an integer primary key called id, unless you set primary_key=True on one of your fields.
from django.db import models
from django_view_models.models import ViewModel, MaterializedViewModel
class Book(models.Model):
title = models.TextField()
is_good = models.BooleanField()
# create a ViewModel with a manual query
class GoodBook(ViewModel):
title = models.TextField()
VIEW_DEFINITION = '''
SELECT id, title
FROM my_app.book
WHERE is_good = true
'''
# create a ViewModel, and use Django's ORM to create the query
class BadBook(ViewModel):
title = models.TextField()
def view_query():
return Book.objects.filter(is_good=False).values('id', 'title')
Release files for django-view-models 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_view_models-0.1.0.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_view_models-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.5 kB
Release files / django_view_models-0.1.0.tar.gz
| Download URL | django_view_models-0.1.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8cc2d7ae4ac0c97890b0fcf59268b78c3842b457a1a1c88f613b20bbdd9965a2
|
|
BLAKE2b-256 checksum How to use checksums |
2fc71fb56ccbf82855ddc2ea6a8bb9181913bda516984d3309bb06e4b1fb7e88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.10.1 urllib3/1.26.7 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|
Release files / django_view_models-0.1.0-py3-none-any.whl
| Download URL | django_view_models-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1799de6c858a43be2947fd2bc29e83001dcb1603b8b218f9f28f14d04b3bd95
|
|
BLAKE2b-256 checksum How to use checksums |
887cb342967dc53e463d8ff4f796a85d678a47a0bfddc1db8440b9c3ee853291
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.10.1 urllib3/1.26.7 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|