-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
73 lines (61 loc) · 1.95 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Django
from django.template.response import TemplateResponse
# Django-DataTables
import datatables
# Django-FortuneCookie
from fortunecookie.models import *
class FortuneCookieTable(datatables.DataTable):
# pk = datatables.CheckboxColumn()
fortune = datatables.Column(
label='Your Fortune',
sort_field='fortune_lower',
)
fortune_lower = datatables.Column(
label='Lower Fortune',
bVisible=False,
bSearchable=False,
)
lucky_numbers = datatables.Column(
display_field='lucky_numbers_display',
sClass='okie',
asSorting=["asc", "desc", "desc"],
bSearchable=False,
)
chinese_word = datatables.Column(
label='Chinese Word',
sort_field='chinese_word.english_word',
search_field='chinese_word.english_word',
sClass='okie',
# bSearchable=False,
)
def get_queryset(self):
qs = self.get_default_queryset()
qs = qs.extra(select={
'fortune_lower': 'LOWER(fortune)',
})
return qs
class Meta:
model = FortuneCookie
bInfo = True
bSort = True
bPaginate = False
bJQueryUI = True
sScrollY = '200px'
aaSorting = [[2, "desc"]]
aLengthMenu = [[3, 10, 25, 50, -1], [3, 10, 25, 50, "All"]]
# fnInitComplete = '''function(oSettings, json) {
# alert("Init Complete!"); }'
# bServerSide = True
# sAjaxSource = '/'
# fnServerData = '''function( sUrl, aoData, fnCallback ) {
# $.ajax( {
# "url": sUrl,
# "data": aoData,
# "success": fnCallback,
# "dataType": "jsonp",
# "cache": false} );}'''
@datatables.datatable(FortuneCookieTable, name='fct')
def index(request):
qs = request.fct.get_queryset()
request.fct.update_queryset(qs)
return TemplateResponse(request, 'index.html', {'table': request.fct})