HTML table representation for SQLAlchemy .
SQLAlchemy to <table>
Assume you have an entity called Music. It looks like the below.
class Music(Base):
id = Column(Integer, primary_key=True)
name = Column(Unicode, nullable=False)
The following code renders a sortable <table> consisting of a list of music.
from dodotable.schema import Table, Column
table = Table(
cls=Music,
label='music table',
columns=[
Column(attr='id', label=u'id', order_by='id.desc'),
Column(attr='name', label=u'name'),
],
sqlalchemy_session=session
)
print(table.select(offset=0, limit=10).__html__())
Using with Flask
Flask uses Jinja2 as the template engine. As they mentioned on document[1]_, it is one of strategy that implement __html__ on every class inherit dodotable.schema.Renderable to convert a instance into HTML directly in Jinja2. Re-write the example written before with Flask.
from dodotable.schema import Table, Column
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/musics/', methods=['GET'])
def list_musics():
table = Table(
cls=Music,
label='music table',
columns=[
Column(attr='id', label=u'id',
order_by=request.args.get('order_by')),
Column(attr='name', label=u'name'),
],
sqlalchemy_session=session
)
return render_template(
'list_musics.html',
table=table.select(limit=request.args.get('limit'),
offset=request.args.get('offset'))
)
And list_musics.html which is jinja2 template is look like below.
<html>
<body>
{{ table }}
</body>
</html>
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dodotable-0.1.3.tar.gz.
File metadata
- Download URL: dodotable-0.1.3.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
174cb7a4657eb8903434b37ac7e135489584c27003ecab6c03d62c907a10a0b4
|
|
| MD5 |
456804812f750b388236b46e665d5701
|
|
| BLAKE2b-256 |
aebbb3c0c3836cd63479080a84abca62727c520bcddcb17604e1267934c7b405
|
File details
Details for the file dodotable-0.1.3-py2.py3-none-any.whl.
File metadata
- Download URL: dodotable-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d2789fd10e66d3f479ac7c32568feae6e0ac24db4562adccd8716ae5e336580
|
|
| MD5 |
752d0429da090287c08bd837c167acf4
|
|
| BLAKE2b-256 |
041a3a02e3e8777c140e25231f7319d73819d9fe05fe3f6384263788864e65c7
|