用于完整数据表服务器处理实现的轻量级django类
django-datatables-ajax的Python项目详细描述
#django datatables server processing
用于完整数据表服务器处理实现的轻量级django类。
https://datatables.net/examples/data_sources/server_side.html
我在网上找到的东西都做了测试,但都有同样的问题,他们不能管理好外键关系。毕竟,这是我自己做的。
这段代码是在datatables 1.10.+和django 1.10.+.
上测试的,只要把datatables放在html模板中就行了,就像这样:
``html
<;!--jquery-->;
<;script src=“/statics/js/vendors/jquery/dist/jquery.min.js”>;
<;<;!--数据表-->;
<;script src=“/statics/js/vendors/datatables.net/js/jquery.datatables.js”>;
<;!--数据表-->;
<;script>;
$(document).ready(function(){
$('.datatable responsieserverserverside').datatable({
“alengthmenu”:[
[25,50,100,500,],//-1],
;[25,50,100,100,500,]//“all”]
>,
;[25,50,100,100,500,]//“all”]]
]],
“寻呼”
“寻呼”;“寻呼”:真,
真,
。160;“响应”:true,
“处理”:true,
“服务器端”:true,
“服务器端”:true,
“ajax”:“{%url'appnamespace:viewnname_json“%”,
///post方法示例这里这里的方法示例
//“ajax”:{
{
//“ajax”:“ajax”:“{%url'appnamespace:viewnname_json“%”,
/////post方法示例这里这里的方法示例
//“ajax”:“{%url'appnamespace:viewnname _json“%”,
“处理”:true,
“处理”:true,
“a //~ method: 'post',
//~ data: function(args) {
//~ return {
//~ "args": JSON.stringify(args)
//~ };
//~ }
//~ },
});
};
<;/脚本>;
```
Requirements
----
git+https://github.com/peppelinux/django datatables ajax.git
`````
http404
来自django.http.response import httpresponseredirect
来自django.http import jsonresponse
来自.datatables import djangodatatablesserverproc
@需要登录
定义数据表数据(请求):
radcheck=get-radcheck-active(请求)
radius-accounts=get-radius-accounts(请求,radcheck)
model=radiusostauth
columns=['pk'、'username'、'reply'、'calling_station_id','date']
base_query=model.objects.filter(username_u in=[i.username for i in radius_accounts]).exclude(calling_station_u id=''.order_by('-date')
def get_queryset(self):
if self.search_key:
self.aqs=base_q query.filter(
q(用户名iCONTAINS=self.search_key)
q(回复iCONTAINS=self.search_key)
q(呼叫iCONTAINS=self.search_key))
其他:
self.aqs=基本查询.filter(username=radcheck.username)
dtd=dtd(请求、模型、列)
return jsonresponse(dtd.get_dict())
```````
create an url resource
``````
from django.conf.url import include,url
来自django.contrib.auth.decorators导入登录名必需
=‘datatable_json’,
]
````
用于完整数据表服务器处理实现的轻量级django类。
https://datatables.net/examples/data_sources/server_side.html
我在网上找到的东西都做了测试,但都有同样的问题,他们不能管理好外键关系。毕竟,这是我自己做的。
这段代码是在datatables 1.10.+和django 1.10.+.
上测试的,只要把datatables放在html模板中就行了,就像这样:
``html
<;!--jquery-->;
<;script src=“/statics/js/vendors/jquery/dist/jquery.min.js”>;
<;<;!--数据表-->;
<;script src=“/statics/js/vendors/datatables.net/js/jquery.datatables.js”>;
<;!--数据表-->;
<;script>;
$(document).ready(function(){
$('.datatable responsieserverserverside').datatable({
“alengthmenu”:[
[25,50,100,500,],//-1],
;[25,50,100,100,500,]//“all”]
>,
;[25,50,100,100,500,]//“all”]]
]],
“寻呼”
“寻呼”;“寻呼”:真,
真,
。160;“响应”:true,
“处理”:true,
“服务器端”:true,
“服务器端”:true,
“ajax”:“{%url'appnamespace:viewnname_json“%”,
///post方法示例这里这里的方法示例
//“ajax”:{
{
//“ajax”:“ajax”:“{%url'appnamespace:viewnname_json“%”,
/////post方法示例这里这里的方法示例
//“ajax”:“{%url'appnamespace:viewnname _json“%”,
“处理”:true,
“处理”:true,
“a //~ method: 'post',
//~ data: function(args) {
//~ return {
//~ "args": JSON.stringify(args)
//~ };
//~ }
//~ },
});
};
<;/脚本>;
```
Requirements
----
git+https://github.com/peppelinux/django datatables ajax.git
`````
http404
来自django.http.response import httpresponseredirect
来自django.http import jsonresponse
来自.datatables import djangodatatablesserverproc
@需要登录
定义数据表数据(请求):
radcheck=get-radcheck-active(请求)
radius-accounts=get-radius-accounts(请求,radcheck)
model=radiusostauth
columns=['pk'、'username'、'reply'、'calling_station_id','date']
base_query=model.objects.filter(username_u in=[i.username for i in radius_accounts]).exclude(calling_station_u id=''.order_by('-date')
if self.search_key:
self.aqs=base_q query.filter(
q(用户名iCONTAINS=self.search_key)
q(回复iCONTAINS=self.search_key)
q(呼叫iCONTAINS=self.search_key))
其他:
self.aqs=基本查询.filter(username=radcheck.username)
dtd=dtd(请求、模型、列)
return jsonresponse(dtd.get_dict())
```````
create an url resource
``````
from django.conf.url import include,url
来自django.contrib.auth.decorators导入登录名必需
=‘datatable_json’,
]
````