A simple Django app to handle database views.
Project description
A simple pluggable application that allows to work with database views.
So far only MySQL is supported as backend, but more could be added if necessary.
Quick start
Add “dbview” to your INSTALLED_APPS settings like this:
INSTALLED_APPS = ( ... 'dbview', )
In your models.py create classes which extend dbview.DbView like this:
from django.db import models from dbview import DbView class ModelA(models.Model): fielda = models.CharField() fieldc = models.IntegerField() class MyView(DbView): fieldA = models.OneToOneField(ModelA, primary_key=True, db_column='fielda__id') fieldB = models.IntegerField(blank=True, null=True, db_column='fieldb') @classmethod def view(klass): ''' This method returns the SQL string that creates the view, in this example fieldB is the result of annotating another column ''' qs = modelA.objects.all().\ annotate(fieldb=models.Sum('fieldc')) .\ annotate(fielda__id=models.F('pk')) .\ order_by('fielda__id') .\ values('fielda__id', 'fieldb') return str(qs.query)
Then create a migration point for your view generation, edit that migration and modify it, add: from dbview import CreateView and replace the line the call to migrations.CreateModel with CreateView.
Migrate your database and start using your database views.
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
Built Distribution
Close
Hashes for django-database-view-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d424831f0a26bd9bc2c5a1e5159f4233b9bab6c3d05837c53ffc9f10f0b6021 |
|
MD5 | 479db27058cc6457e3df56b10369ad6a |
|
BLAKE2b-256 | 57619682577fd96e9c96ef996167ca0d0163aa3c082724cd523724a5c011679d |
Close
Hashes for django_database_view-0.1.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39279bc0a448b585ef776a7e9e24f7f24c9ff4f4b30a3badc189125637cd634c |
|
MD5 | 9de7cb1500097ad285de7173107ddc0b |
|
BLAKE2b-256 | 9af0c09d36ced8a689b3cb39c0c41c137d75e294c43eee078d9d5520a6574495 |