%global _empty_manifest_terminate_build 0 Name: python-django-database-view Version: 0.3.0 Release: 1 Summary: A simple Django app to handle database views. License: MIT URL: https://github.com/manuelnaranjo/django-database-view Source0: https://mirrors.nju.edu.cn/pypi/web/packages/90/10/8d5f427692f766150bf77e236501cec1a1d35097f608d0480eb0e897533e/django-database-view-0.3.0.tar.gz BuildArch: noarch %description 1. Install the package:: pip install django-database-view 2. In your ``models.py`` create classes which extend ``dbview.models.DbView`` like this: from django.db import models from dbview.models 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(cls): """ 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) Alternatively ``get_view_str`` method could be used to write a custom SQL: class MyView(DbView): # ... @classmethod def get_view_str(cls): return """ CREATE VIEW my_view AS ( SELECT ... )""" 3. Then create a migration point for your view generation, edit that migration and modify it, add: ``from dbview.helpers import CreateView`` and replace the line the call to ``migrations.CreateModel`` with ``CreateView``. 4. Migrate your database and start using your database views. %package -n python3-django-database-view Summary: A simple Django app to handle database views. Provides: python-django-database-view BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-django-database-view 1. Install the package:: pip install django-database-view 2. In your ``models.py`` create classes which extend ``dbview.models.DbView`` like this: from django.db import models from dbview.models 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(cls): """ 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) Alternatively ``get_view_str`` method could be used to write a custom SQL: class MyView(DbView): # ... @classmethod def get_view_str(cls): return """ CREATE VIEW my_view AS ( SELECT ... )""" 3. Then create a migration point for your view generation, edit that migration and modify it, add: ``from dbview.helpers import CreateView`` and replace the line the call to ``migrations.CreateModel`` with ``CreateView``. 4. Migrate your database and start using your database views. %package help Summary: Development documents and examples for django-database-view Provides: python3-django-database-view-doc %description help 1. Install the package:: pip install django-database-view 2. In your ``models.py`` create classes which extend ``dbview.models.DbView`` like this: from django.db import models from dbview.models 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(cls): """ 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) Alternatively ``get_view_str`` method could be used to write a custom SQL: class MyView(DbView): # ... @classmethod def get_view_str(cls): return """ CREATE VIEW my_view AS ( SELECT ... )""" 3. Then create a migration point for your view generation, edit that migration and modify it, add: ``from dbview.helpers import CreateView`` and replace the line the call to ``migrations.CreateModel`` with ``CreateView``. 4. Migrate your database and start using your database views. %prep %autosetup -n django-database-view-0.3.0 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-django-database-view -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Wed May 10 2023 Python_Bot - 0.3.0-1 - Package Spec generated