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
Hashes for Flask-DataTables-peewee-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66b583547d054fa8af07c9381f48ee6cb9dbd049e47c846d0bba33d3b78b32ef |
|
MD5 | f78c392e0945ff2c63adadd3b258d075 |
|
BLAKE2b-256 | a970815225ab2bcd66542af28f7875500f79263f3ca93f02e18690faef64874d |
Hashes for Flask_DataTables_peewee-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b88f44091886f79ed4fe966caa3f633a3531ee60d28c77e8be8c7b9dd704f3cb |
|
MD5 | fa2e005788d3fdd1289bd73579c2c86a |
|
BLAKE2b-256 | c3bf6d733c78904d488c92fa5d6975f339cfcecf450d99a36767b54ec1963f9b |