Skip to main content

django_view_models

Designed for Postgres. May or may not work with other databases.

Installation/Usage

  • pip install django_view_models
  • add django_view_models to INSTALLED_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)

Source distribution for django-view-models 0.1.0
File Size Uploaded
django_view_models-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-view-models 0.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page