Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyohei/django-view-table
Plugin to create view table in Django.
https://github.com/pyohei/django-view-table
django python viewtable
Last synced: 9 days ago
JSON representation
Plugin to create view table in Django.
- Host: GitHub
- URL: https://github.com/pyohei/django-view-table
- Owner: pyohei
- License: mit
- Created: 2019-09-16T11:42:19.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T23:26:44.000Z (7 months ago)
- Last Synced: 2024-04-14T13:10:39.961Z (7 months ago)
- Topics: django, python, viewtable
- Language: Python
- Homepage:
- Size: 54.7 KB
- Stars: 14
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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## Installation & Setup
```
pip install django-view-table
```After install, you can set your `INSTALLED_APPS`
```python
INSTALLED_APPS = [
'view_table',
]
```## Usage
### Create model
You need the three step.
* Import `view_table` module
* Inherit `ViewTable`
* Impliment `get_query` methodThe 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.
```python
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.
```bash
python manage.py createviewtable
```## Development
I prepare application for this plugin application.
* https://github.com/pyohei/django-view-table
## License
MIT