Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

django-view-table

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-view-table

Django view table plugin

  • 1.0.1
  • PyPI
  • Socket score

Maintainers
1

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.

  • https://github.com/pyohei/django-view-table

License

MIT

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc