Skip to main content

Django view table plugin

Project description

django-view-table

Plugin to create view table in Django.
This plugin enable you to create view table in Django model.

Support Database

  • SQLite3
  • PostgreSQL
  • MySQL
  • (TBC)Oracle Database

Installation & Setup

pip install django-view-table

After install, you can set your INSTALLED_APPS

INSTALLED_APPS = [
    'viewtable',
]

Usage

Create model

You need the three step.

  • Import view_table module
  • Inherit ViewTable
  • Impliment get_query method

The method get_query should return select sql statement.
You can write sql statement as raw sql or django model object.

This is a simple example.

from django.db import models
from view_table.models import ViewTable


# Base table
class Book(models.Model):
    name = models.CharField(max_length=100)
    category = models.CharField(max_length=100)


# View table
class Books(ViewTable):
    category = models.CharField(max_length=100)
    count = models.IntegerField()

    # You must implement get_query method.
    @classmethod
    def get_query(self):
        return Book.objects.values('category').annotate(count=models.Count('category')).query
        # You can also write:
        # return 'SELECT "polls_book"."category", COUNT("polls_book"."category") AS "count" FROM "polls_book" GROUP BY "polls_book"."category"' 

Run command

After Django migration, you can create view tables the below command.

python manage.py createviewtable

Development

I prepare application for this plugin application.

License

MIT

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-view-table-1.0.1.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file django-view-table-1.0.1.tar.gz.

File metadata

  • Download URL: django-view-table-1.0.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.1

File hashes

Hashes for django-view-table-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2992220533285b8356c14758de1a80b8a27d934132ca9ec9eac5a7ae8c0ea773
MD5 ca44861a2616596121114e5d90c54b7a
BLAKE2b-256 c77a40dbb9df976f8fde30971e57d48fb7bdc8dfeaf9b0e0d196bb289545087b

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