Flask integration with DataTables and peewee.
Project description
As DataTables is a quite power and useful JavaScript library for manipulating and displaying data, we intended to make integration of the client-side DataTables scripts with the server-side processing based on Flask and peewee.
Installation
Note
As we have noticed, there’s already a Flask-DataTables library available on PyPI. However, this package was intended for integration with SQLAlchemy instead of peewee.
To start with, simply install the Flask-DataTables package from PyPI:
pip install Flask-DataTables-peewee
or should you prefer the bleeding edge version:
git clone https://github.com/JarryShaw/Flask-DataTables.git
cd Flask-DataTables
pip install .
Usage
Flask-DataTables is quite simple to use, just declare your data model in the preferable way from peewee and voilà, that’s it.
Taking examples from the peewee documentation, we can have a DataTables integrated data model just as below:
from flask import Flask
from flask_datatables import (CharField, DataTable, DateTimeField,
ForeignKeyField, Metadata, TextField)
DATABASE = 'postgresql://postgres:password@localhost:5432/my_database'
app = Flask(__name__)
app.config.from_object(__name__)
db_wrapper = DataTable(app)
class User(db_wrapper.Model):
username = CharField(unique=True)
class Meta(Metadata):
datatables = True
class Tweet(db_wrapper.Model):
user = ForeignKeyField(User, backref='tweets')
content = TextField()
timestamp = DateTimeField(default=datetime.datetime.now)
class Meta(Metadata):
datatables = True
And now, you may simply call Tweet.search() to perform the server-side processing queries.
See Also
It is also possible to customise the orderable and/or searchable fields through flask_datatables.fields.Field parameters, and their corresponding behaviours by subclassing the flask_datatables.fields.Field classes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Flask-DataTables-peewee-0.1.0.tar.gz
.
File metadata
- Download URL: Flask-DataTables-peewee-0.1.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 703fd67e971f285f4015757ae51b154676cad3b4bab64a352ee6fd9acbb7e48a |
|
MD5 | 65f7a0fb40647d023185ffadc6d3bd7b |
|
BLAKE2b-256 | 7fb7697cfdda0c6c5507f708803c6811d4696f3f43714a6e384077037ff7a53e |
File details
Details for the file Flask_DataTables_peewee-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_DataTables_peewee-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 873cdfdea4ab831bd5413a8432b368503054445a7c47fce3bd2d59c3c544bda5 |
|
MD5 | e839ac69d09e4ce9215a2cead56e4921 |
|
BLAKE2b-256 | 26883d662eeafa908610cb2aa32964e46ff90c1be2ea1a206dd5e93cea3af8b3 |