Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-DataTables-peewee-0.1.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

Flask_DataTables_peewee-0.1.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file Flask-DataTables-peewee-0.1.2.tar.gz.

File metadata

  • Download URL: Flask-DataTables-peewee-0.1.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

File hashes

Hashes for Flask-DataTables-peewee-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3a386113e1819db24f19090848e03581632496b8b9ced274186b5be0dfbbfcfc
MD5 1f19d12e7025851f17d241968905252e
BLAKE2b-256 667aca9d79a8403a1f34b5c57965216592295610a7b377485ca114b6d2e99f7c

See more details on using hashes here.

File details

Details for the file Flask_DataTables_peewee-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: Flask_DataTables_peewee-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

File hashes

Hashes for Flask_DataTables_peewee-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 62fc8154338d7fbc983e927b7a40aff78e6a96a8385dff6a170b24698df8bcac
MD5 dc1bb1017adff04e0c405f0cb650c0b2
BLAKE2b-256 3a0c002e8ff4a59ede6561da83a39e9a4675193593f474bc8d293595999777a1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page