datatables-mongoengine-0.1.7
توضیحات
MongoEngine QuerySet class for populating DataTables from MongoEngine.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | datatables-mongoengine-0.1.7 |
| نام | datatables-mongoengine |
| نسخه کتابخانه | 0.1.7 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Paul Olsen |
| ایمیل نویسنده | paul@wholeshoot.com |
| آدرس صفحه اصلی | https://github.com/pauljolsen/datatables-mongoengine |
| آدرس اینترنتی | https://pypi.org/project/datatables-mongoengine/ |
| مجوز | MIT |
# DataTables with MongoEngine
The `DataTablesManager` class can be used instead of the default MongoEngine
`QuerySet` class to add a `datatables` method for returning results as required by the
jQuery plugin DataTables.
## Installation
pip install datatables-mongoengine
## Example
Here's an example for Flask.
#### models.py
from mongoengine import Document, StringField, ListField
from datatables_mongoengine import DataTablesManager
class Links(Document):
"""The MongoEngine ODM class for the links collection."""
meta = {
"queryset_class": DataTablesManager
}
name = StringField()
category = StringField()
link = StringField()
group = ListField()
#### routes.py
from flask import request, g, jsonify
from app import app
from app.models import Links
@app.route("/ajax/links", methods=["POST"])
def ajax_links():
"""Get results from MongoDB for DataTables."""
data = request.get_json()
custom_filter = {
'group': g.user.group
}
results = Links.objects.datatables(data, **custom_filter)
return jsonify(results)
Note that you can inject any filter you want server-side, like I do above to make sure
the results all match the current user's group.
#### app.js
$(document).ready( function () {
$('#example').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '/ajax/links',
dataSrc: 'data',
type: 'POST',
contentType: 'application/json',
data: function (d) {
return JSON.stringify(d)
}
},
columns: [
{ data: 'name'},
{ data: 'category'},
{ data: 'link'}
],
});
نیازمندی
| مقدار | نام |
|---|---|
| - | mongoengine |
نحوه نصب
نصب پکیج whl datatables-mongoengine-0.1.7:
pip install datatables-mongoengine-0.1.7.whl
نصب پکیج tar.gz datatables-mongoengine-0.1.7:
pip install datatables-mongoengine-0.1.7.tar.gz