I learned sql \"view\" as a virtual table to facilitate the SQL operations, like
MySQL [distributor]> CREATE VIEW CustomerEMailList AS
-> SELECT cust_
I created a Django plugin which you can create a view table. You can check it here, on pypi.org
Install with pip install django-view-table
and set INSTALLED_APPS
like this:
INSTALLED_APPS = [
'viewtable',
]
And so, a view table model can be written as follows:
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):
# Select sql statement
return Book.objects.values('category').annotate(count=models.Count('category')).query
Finally, create the table:
python manage.py createviewtable