昨日内容:
ORM高级查询
-filter id=3 id__gt=3 id__lt=3 id__lte=3 id__gte=3 -in /not in .filter(id__in=[]) in .exclude(id__in=[]) not in -between......and .filter(id__range=[]) -like .filter(name__startswith='XX') like 'XX%' .filter(name_istartswith='XX') #忽略大小写 .filter(name__endswith='XX') like'%XX' .filter(name__contains='XX') like'%XX%' .filter(name_regax='^XX$') like'%XX%'精准匹配 -or from django.db.models import Q Q和|连用为or &为and -order by models.UserInfo.objects.all().order_by('id')#升序#('-id')则为降序 #若有2个值,则第一个先排序,第二个后排序 -group by from django.db.models import Sum,Count,Min,Max models.UserInfo.objects.values('name').annota1te(xx=Sum('age')) models.UserInfo.objects.values('name').annota1te(xx=Sum('age')).filter(XX__gt=50)#二次筛选 -count models.UserInfo.objects.count() -limit分页 models.UserInfo.objects.all()[X,XX]#利用切分来分页 -distinct models.UserInfo.objects.values('XX').distinct() -原生SQL from django.db import connection -first -last两个返回的都是对象 "htmlcode">id name age 1 zekai 18 2 lxxx 58 private: id salary sp_id(外键+unique) 1 5000 1 2 4000 2一对一
OneToOneField("表名",null=True)默认要求该字段必须是唯一的unique外键关系
#从母表查询子表的数据
查询一下name='zekai'的这条数据
res = models.UserInfo.objects.filter(name='zekai').first() print(res.private.salary) #res.子表表名小写.子表字段名#从字表查询母表中的数据
查询salary=5000的这个数据所对应的用户的信息
res= models.Private.objects.filter(salary=5000).first() print(res.sp.name,res.sp.age) #res.关联的字段名.母表字段名多对多
相亲模型
boy: id name 1 laowang 2 XXX girl: id name 1 正正 2 连连 3 爱爱 4 凤姐 5 乔碧萝 boy2girl id bid gid 1 1 1 2 1 2 3 1 3 4 2 2 5 2 4 6 2 5 models.py: class Boy(models.Model): bname=models.CharField(max_length=32,null=True) "Boy",null=True) g = models.ForeignKey("Girl",null=True) "htmlcode">from django.core.paginator import Paginator #per_page:每页显示条目数量 #count:数据总个数 #num_pages:总页数 #page_range:总页数的索引范围 #page:page对象 paginator = Paginator(userlist,10) #has_next:是否有下一页 #next_page_number:下一页页码 #has_previous:是否有上一页 #previous_page_number:上一页页码 #object_list:分页之后的数据列表 #number:当前页 #paginator:paginator对象 sers = paginator.page(cur_page) return render(request,'index.html',{"users":users}) "<li><a href='#' aria-label='Previous'><span aria-hidden='true'>«</span></a></li>" else: astr = "<li><a href='/custom/" % (self.cur_page-1) page_list.append(astr) "<a style='display:inline-block; padding:5px;margin:5px;background-color:red;' href='/custom/" % (i, i) astr = "<li class='active'><a href='/custom/" % (i, i) else: # astr = "<a style='display:inline-block; padding:5px;margin:5px' href='/custom/" % (i, i) astr = "<li><a href='/custom/" % (i, i) page_list.append(astr) "<li><a href='#' aria-label='Next'><span aria-hidden='true'>»</span></a></li>" else: astr = "<li><a href='/custom/" % (self.cur_page+1) page_list.append(astr) " ".join(page_list) "custom.html", {"user_list":user_list, "page":page})安全攻击
- -XSS
- -csrf
- -sql注入
以上就是本次介绍的全部相关知识点,感谢大家对的支持。
标签:
djano,分页
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“djano一对一、多对多、分页实例代码”评论...
更新日志
2024年10月07日
2024年10月07日
- 群星《前途海量 电影原声专辑》[FLAC/分轨][227.78MB]
- 张信哲.1992-知道新曲与精丫巨石】【WAV+CUE】
- 王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】
- 景冈山.1996-我的眼里只有你【大地唱片】【WAV+CUE】
- 群星《八戒 电影原声带》[320K/MP3][188.97MB]
- 群星《我的阿勒泰 影视原声带》[320K/MP3][139.47MB]
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]