Skip to main content

A framework for managing database views based on Django

Project description

django_views

What does this support?

This package adds support to Django for writing Postgres views using:

  • Raw SQL
  • Querysets

They look something like this:

class MySQLView(PostgresViewFromSQL):
    sql = """
       SELECT col_a, col_b FROM table_1;
    """
class MyQuerysetView(PostgresViewFromQueryset):
    
    def get_queryset(self):
        return (
            Table1
            .objects
            .values('col_a', 'col_b')
        )

What does this not support?

Reading the views in an ORM-friendly way.

When should I use this?

Our use-case is for a database which is managed by Django in which we would like to provide an analytics-friendly representation of some of our data. This involves giving analytics direct access to our database (whilst using a permissions framework), but using views to expose the data in a more simple way, as well as obscuring data which we consider personally identifiable/sensitive.

There are other frameworks existing which do similar things, usually including reads via the ORM. We found that these packages all generate migrations (despite being unmanaged) and we wanted to remove this from the django migrations process altogether - there seemed to be no value add by including migrations and they would just muddy our migration states.

Cool! But how do I use this?

  • Add 'django_views' to your INSTALLED_APPS
  • Create a postgres_views.py (file or package) inside any app
  • Add a PostgresViewFromQueryset or PostgresViewFromSQL to your postgres_views.py (as above)
  • run ./manage.py sync_views

What's still to come?

  • Views depending on other views - this needs some small dependency analysis which we haven't implemented as of yet.
  • Making the package more configurable using settings.
  • Consideration of implementing reads using the ORM
  • Consideration of 0 downtime deployments with views. Note, this can still be achieved with the current implementation, but a bad migration (with a view depending) could cascade a view and create downtime. Ideally migrations + view creation should happen in a single transaction.
  • Actual tests!

Project details


Download files

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

Source Distribution

django-orm-views-0.0.1rc1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

django_orm_views-0.0.1rc1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file django-orm-views-0.0.1rc1.tar.gz.

File metadata

  • Download URL: django-orm-views-0.0.1rc1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for django-orm-views-0.0.1rc1.tar.gz
Algorithm Hash digest
SHA256 314f530ee9880e9c29ce706ee873b3e457231b48a3d8de98e02bf9b610dc3dc4
MD5 aa799798d43fdab5c884a0fac6da55c4
BLAKE2b-256 f34b40f04a7fc3c75cc2b630a670d7d4e792d3677a064be65bb55a2b9b229145

See more details on using hashes here.

File details

Details for the file django_orm_views-0.0.1rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_orm_views-0.0.1rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a050096df399eb626feacfff00e5d47cb1f5f5ef89ee5abac7123ce01f91e68
MD5 060bf9c182713f93f2594279daf3af77
BLAKE2b-256 74e7949ab88768df29490893bb5023e04c94ad5f37a5e495d9ecae6a421bfa6f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page