Integrates SQLAlchemy with datatables
Project description
Installation
The package is available on PyPI
pip install datatables
Quickstart
models.py
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
full_name = Column(Text)
created_at = Column(DateTime, default=datetime.datetime.utcnow)
address = relationship("Address", uselist=False, backref="user")
class Address(Base):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
description = Column(Text, unique=True)
user_id = Column(Integer, ForeignKey('users.id'))
views.py
@view_config(route_name="data", request_method="GET", renderer="json")
def users_data(request):
table = DataTable(request.params, User, User.query, [
"id",
("name", "full_name"),
("address", "address.description"),
])
table.add_data(link=lambda o: request.route_url("view_user", id=o.id))
return table.json()
template.jinja2
<table class="table" id="simple-example">
<thead>
<tr>
<th>Id</th>
<th>User name</th>
<th>Address description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$("#clients_list").dataTable({
serverSide: true,
processing: true,
ajax: "{{ request.route_url("data") }}",
columns: [
{
data: "id",
"render": function(data, type, row){
return $("<div>").append($("<a/>").attr("href", row.DT_RowData.link).text(data)).html();
}
},
{ data: "name" },
{ data: "address" }
]
</script>
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
datatables-0.2.zip
(7.4 kB
view hashes)