Create View Table in Django(My plugin)

Shohei Mukai
1 min readNov 22, 2020

--

Do you have a time to create view table in Django?
I am Yes. But there are no plugins as I know.

And I create Django Plugin which enable to create view table! This is very simple plugin.
I think some people want this feature(maybe)😁.

Usage

Install from pip:

pip install django-view-table 

Add ‘viewtable’ in your Django settings.py:

INSTALLED_APPS = [
'viewtable',
]

You can create view table model as follow:

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()

@classmethod
def get_query(self):
return Book.objects.values('category').annotate(count=models.Count('category')).query

After migration, you run the below command.

./manage.py createviewtable

You can find your view table!!

View table model works as Django original model object. Because this is merely inherited Django model.

If you have curious, please see the GitHub. I write how to install and use this plugin.

--

--