我不想使用原始 SQL。但我不知道如何更改此代码。
看了各种资料,想办法不使用SQL raw,但是失败了。我不知道如何改变这一点。
def listSpecificPageWork(request):
current_page = request.GET['current_page']
totalCnt = DjangoBoard.objects.all().count()
print 'current_page=', current_page
boardList = DjangoBoard.objects.raw('SELECT Z.* FROM(SELECT X.*, round((rownum / %s)+0.5) as page FROM(SELECT ID,SUBJECT,NAME, CREATED_DATE, MAIL,MEMO,HITS FROM BOARD_DJANGOBOARD ORDER BY ID DESC)X)Z WHERE page = %s', [rowsPerPage, current_page])
print 'boardList=',boardList, 'count()=', totalCnt
pagingHelperIns = pagingHelper();
totalPageList = pagingHelperIns.getTotalPageList( totalCnt, rowsPerPage)
print 'totalPageList', totalPageList
return render_to_response('listSpecificPage.html', {'boardList': boardList, 'totalCnt': totalCnt, 'current_page':int(current_page), 'totalPageList':totalPageList} )
# -*- coding: utf-8 -*-
class pagingHelper:
"paging helper class"
def getTotalPageList(self, total_cnt, rowsPerPage):
if((total_cnt % rowsPerPage) == 0):
self.total_pages = total_cnt/rowsPerPage;
print 'getTotalPage #1'
else:
self.total_pages = (total_cnt/rowsPerPage) + 1;
print 'getTotalPage #2'
self.totalPageList = []
for j in range(self.total_pages):
self.totalPageList.append(j+1)
return self.totalPageList
def __init__(self):
self.total_pages = 0
self.totalPageList = 0
错误:没有这样的列:rownum
我想更改boardList。
猛跑小猪
相关分类