Automatically create editable grids in browser from SQLAlchemy models
Project description
flask extension for making editable grids from sqlalchemy models. In the example directory of the repo you can find a mimimal flask app demonstrating features and usage of the extension. The code snippets below are all from the example.
Usage
Like other flask extensions, you’ll initialize it with the app. Below is from the “example” application in the repo.
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_gridify import FlaskGridify app = Flask(__name__) db = SQLAlchemy(app) # initialize the FlaskGridify extension grid = FlaskGridify(app, flask_sqlalchemy_db=db, root_url_prefix='/grids')
Then for each model class you want grids for you’ll call the gridify function of the grid object above and pass in the SQLAlchemy model class
from .models import User, Note grid.gridify(User) grid.gridify(Note)
When you run the app, you’ll have the following URL routes:
/
This route demonstrates useage of the Jinja macros that allow for creation of grids inside of your application templates
/grids/note
This is the grid page created for the Note model
/grids/user
This is the grid page created for the User model
Additionally, the extension will create and use a REST API for each gridified model class that can be used by your application. It uses the FlaskRestless extension so information on the formatting and URLs can be found there
Using FlaskGridify in Templates
The extension also exposes Jinja template macros you can use to embed the editable grids for models in your pages. In the example/templates/index.html.jinja template file we create grids for the User and Note model classes like so:
<div id="user-grid"></div> <div id="note-grid"></div> {{ macros.create_grid("user-grid", "user", GRID_REGISTRY["user"]) }} {{ macros.create_grid("note-grid", "note", GRID_REGISTRY["note"]) }}
Developer information
This project uses a Makefile to build, upload and run example app. You’ll need to have installed your pipenv with --dev to ensure you have the necessary packages for development.
make build
this will build a source distribution of the package
make upload
this will build the package and upload it to pypi
make run
this runs the example app in the repo
TODO
Add Enum field support
Add relationship field support
many to one
many to many
Clean up the exposed macros to avoid reference to GRID_REGISTRY
Dependencies
Server side
Client side
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
File details
Details for the file flask-gridify-0.2.0.tar.gz
.
File metadata
- Download URL: flask-gridify-0.2.0.tar.gz
- Upload date:
- Size: 112.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab6651f8a71ee6e697d62d9d7ee727689fda9eb3b0475057dfe0725aac75d238 |
|
MD5 | ff051c33acc5d90936147448191d8bd9 |
|
BLAKE2b-256 | 21cb1f3efc2d48fe7e3c75d5a1b52e48663b437c5702075ec27aab5cd2544c1e |