PK[Ftdbview/models.pyfrom django.db import models class ViewManager(models.Manager): def bulk_create(self, *args, **kwargs): raise NotImplementedError def create(self, *args, **kwargs): raise NotImplementedError def get_or_create(self, *args, **kwargs): raise NotImplementedError def delete(self, *args, **kwargs): raise NotImplementedError def update(self, *args, **kwargs): raise NotImplementedError class DbView(models.Model): objects = ViewManager() class Meta: abstract = True def delete(self, *args, **kwargs): raise NotImplementedError def save(self, *args, **kwargs): raise NotImplementedError PKjmG.4h[[dbview/__init__.py# placeholder for git from helpers import CreateView, DeleteView from models import DbView PKjmGdbview/helpers.pyfrom django.db import migrations from django.apps import apps class CreateView(migrations.CreateModel): def database_forwards(self, app_label, schema_editor, from_state, to_state): model = to_state.apps.get_model(app_label, self.name) if not self.allow_migrate_model(schema_editor.connection.alias, model): raise models = apps.get_app_config(app_label).models_module model = getattr(models, self.name) sql = 'DROP VIEW IF EXISTS %(table)s;' args = { 'table' : schema_editor.quote_name(model._meta.db_table), } sql = sql % args schema_editor.execute(sql, None) sql = 'CREATE VIEW %(table)s AS %(definition)s' if hasattr(model, 'view'): qs = str(model.view()) else: raise Exception('Your view needs to define either view or ' + 'get_view_str') args['definition'] = qs sql = sql % args schema_editor.execute(sql, None) def database_backwards(self, app_label, schema_editor, from_state, to): model = from_state.apps.get_model(app_label, self.name) sql = 'DROP VIEW IF EXISTS %s' % \ schema_editor.quote_name(model._meta.db_table) schema_editor.execute(sql, None) class DeleteView(migrations.DeleteModel): def database_forwards(self, app_label, schema_editor, from_state, to_state): model = from_state.apps.get_model(app_label, self.name) if self.allow_migrate_model(schema_editor.connection.alias, model): models = apps.get_app_config(app_label).models_module model = getattr(models, self.name) sql = 'DROP VIEW IF EXISTS %(table)s;' args = { 'table' : schema_editor.quote_name(model._meta.db_table), } sql = sql % args schema_editor.execute(sql, None) def database_backwards(self, app_label, schema_editor, from_state, to): model = from_state.apps.get_model(app_label, self.name) sql = 'DROP VIEW IF EXISTS %s' % \ schema_editor.quote_name(model._meta.db_table) schema_editor.execute(sql, None) PKukmG4django_database_view-0.1.3.dist-info/DESCRIPTION.rstdjango-database-view ==================== 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 ----------- 1. Add "dbview" to your INSTALLED\_APPS settings like this: .. code:: python INSTALLED_APPS = ( ... 'dbview', ) 2. In your models.py create classes which extend dbview.DbView like this: .. code:: python 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) 3. 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``. 4. Migrate your database and start using your database views. PKukmG?f2django_database_view-0.1.3.dist-info/metadata.json{"classifiers": ["Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content"], "extensions": {"python.details": {"contacts": [{"email": "naranjo.manuel@gmail.com", "name": "Manuel F. Naranjo", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/manuelnaranjo/django-database-view"}}}, "generator": "bdist_wheel (0.26.0)", "license": "MIT", "metadata_version": "2.0", "name": "django-database-view", "summary": "A simple Django app to handle database views.", "version": "0.1.3"}PKukmGۻY2django_database_view-0.1.3.dist-info/top_level.txtdbview PKukmG''\\*django_database_view-0.1.3.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any PKukmG\ \ -django_database_view-0.1.3.dist-info/METADATAMetadata-Version: 2.0 Name: django-database-view Version: 0.1.3 Summary: A simple Django app to handle database views. Home-page: https://github.com/manuelnaranjo/django-database-view Author: Manuel F. Naranjo Author-email: naranjo.manuel@gmail.com License: MIT Platform: UNKNOWN Classifier: Environment :: Web Environment Classifier: Framework :: Django Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Topic :: Internet :: WWW/HTTP Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content django-database-view ==================== 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 ----------- 1. Add "dbview" to your INSTALLED\_APPS settings like this: .. code:: python INSTALLED_APPS = ( ... 'dbview', ) 2. In your models.py create classes which extend dbview.DbView like this: .. code:: python 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) 3. 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``. 4. Migrate your database and start using your database views. PKukmG+django_database_view-0.1.3.dist-info/RECORDdbview/__init__.py,sha256=JVFc39TAEvQpUvs2cUsKLDWrpgIdoffjk1R1rbiBS9M,91 dbview/helpers.py,sha256=aU9Tu-tgR9BK4T81Y7AD-s8RQsyR2j41_WWojpXnv9g,2215 dbview/models.py,sha256=aJUyMFimw2RCPxB9-nG3ApkyKWGAKadGWO0fZ-2KNuU,690 django_database_view-0.1.3.dist-info/DESCRIPTION.rst,sha256=a35kmCWvyww3EJ8oY0OoA0zsm2T6IgeIR6ot7mvjD_w,1712 django_database_view-0.1.3.dist-info/METADATA,sha256=4gxTmgXPkOP7uFZZVWpaTkcA_6bkwMftSViR2lgJI9Q,2652 django_database_view-0.1.3.dist-info/RECORD,, django_database_view-0.1.3.dist-info/WHEEL,sha256=JTb7YztR8fkPg6aSjc571Q4eiVHCwmUDlX8PhuuqIIE,92 django_database_view-0.1.3.dist-info/metadata.json,sha256=OqHIt3ozKmJa9Y0T-7AUK06MrGnc7avKJKog5mo77wY,1017 django_database_view-0.1.3.dist-info/top_level.txt,sha256=cAu9HRqyyr_0xEKeo3_MmmWMr6WxJR_VDrKuzYAmuWM,7 PK[Ftdbview/models.pyPKjmG.4h[[dbview/__init__.pyPKjmGkdbview/helpers.pyPKukmG4A django_database_view-0.1.3.dist-info/DESCRIPTION.rstPKukmG?f2Cdjango_database_view-0.1.3.dist-info/metadata.jsonPKukmGۻY2django_database_view-0.1.3.dist-info/top_level.txtPKukmG''\\*django_database_view-0.1.3.dist-info/WHEELPKukmG\ \ -django_database_view-0.1.3.dist-info/METADATAPKukmG+.#django_database_view-0.1.3.dist-info/RECORDPK &