日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页...

發布時間:2025/3/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第三百八十九節,Django+Xadmin打造上線標準的在線教育平臺—列表篩選結合分頁

根據用戶的篩選條件來結合分頁

?

?

實現原理就是,當用戶點擊一個篩選條件時,通過get請求方式傳參將篩選的id或者值,傳入邏輯處理就行數據庫條件查詢,將查詢條件值在返回html頁面判斷是否是選中樣式,最后將所有需要關聯的篩選請求加上彼此邏輯處理傳回來的查詢條件值

html請求傳參

黃色背景為請求傳參

紅色背景為邏輯處理傳過來的查詢條件判斷樣式

<div class="wp butler_list_box list"><div class='left'><div class="listoptions"><ul><li><h2>機構類別</h2><div class="cont"><a href="?leib=&chsh={{ chsh_id }}"><span class="{% ifequal lei_bie '' %}active2{% endifequal %}">全部</span></a><a href="?leib=pxjg&chsh={{ chsh_id }}"><span class="{% ifequal lei_bie 'pxjg' %}active2{% endifequal %}">培訓機構</span></a><a href="?leib=gx&chsh={{ chsh_id }}"><span class="{% ifequal lei_bie 'gx' %}active2{% endifequal %}">高校</span></a><a href="?leib=gr&chsh={{ chsh_id }}"><span class="{% ifequal lei_bie 'gr' %}active2{% endifequal %}">個人</span></a></div></li><li><h2>所在地區</h2><div class="more">更多</div><div class="cont"><a href="?chsh=&leib={{ lei_bie }}"><span class="{% ifequal chsh_id '' %}active2{% endifequal %}">全部</span></a>{# 循環城市 #}{% for ch in cheng_shi %}<a href="?chsh={{ ch.id }}&leib={{ lei_bie }}"><span class="{% ifequal chsh_id ch.id|stringformat:'i' %}active2{% endifequal %}">{{ ch.name }}</span></a>{% endfor %}</div></li></ul></div>

?

邏輯處理

from django.shortcuts import render, HttpResponse, redirect # 導入django向瀏覽器返回方法 from django.views.generic.base import View from django.db.models import F,Q from pure_pagination import Paginator, EmptyPage, PageNotAnIntegerfrom app_organization.models import CityDict, CourseOrg # 數據庫表class org_list(View):def get(self, request):# 課程機構ji_gou = CourseOrg.objects.all() # 獲取數據庫的所有數據# 城市帥選cheng_shi = CityDict.objects.all()chsh_id = request.GET.get('chsh', '') # 獲取用戶點擊了城市傳過來的城市idif chsh_id:ji_gou = ji_gou.filter(city_id=chsh_id) # 帥選出指定城市的數據# 類別帥選lei_bie = request.GET.get('leib', '') # 獲取用戶點擊了城市傳過來的城市idif lei_bie:ji_gou = ji_gou.filter(category=lei_bie) # 帥選出指定城市的數據 ji_gou_shu = ji_gou.count() # 統計獲取到的數量# 分頁功能try:page = request.GET.get('page', 1) # 獲取當前頁碼,如果沒有默認1except PageNotAnInteger: # 如果獲取頁碼出錯,默認1page = 1p = Paginator(ji_gou, 4, request=request) # 執行分頁函數,參數1數據庫的數據,參數2顯示多少條數據,參數3request people = p.page(page) # 返回一個,包含了分頁數據和分頁導航的對象return render(request, 'org_list.html', {'cheng_shi': cheng_shi, # 城市數據'people': people, # 將分頁對象傳到html頁面'ji_gou_shu': ji_gou_shu, # 機構數量'chsh_id': chsh_id, # 城市帥選ID'lei_bie': lei_bie # 類別 })def post(self, request):pass

?

轉載于:https://www.cnblogs.com/adc8868/p/7542437.html

總結

以上是生活随笔為你收集整理的第三百八十九节,Django+Xadmin打造上线标准的在线教育平台—列表筛选结合分页...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。