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')

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_view_models-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_view_models-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file django_view_models-0.1.0.tar.gz.

File metadata

  • Download URL: django_view_models-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django_view_models-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8cc2d7ae4ac0c97890b0fcf59268b78c3842b457a1a1c88f613b20bbdd9965a2
MD5 49c31333d6d865578603c60aaea5395a
BLAKE2b-256 2fc71fb56ccbf82855ddc2ea6a8bb9181913bda516984d3309bb06e4b1fb7e88

See more details on using hashes here.

File details

Details for the file django_view_models-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_view_models-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_view_models-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1799de6c858a43be2947fd2bc29e83001dcb1603b8b218f9f28f14d04b3bd95
MD5 2a3385667279cb5a1ec5950d51dcc13b
BLAKE2b-256 887cb342967dc53e463d8ff4f796a85d678a47a0bfddc1db8440b9c3ee853291

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page