Django 字段查询谓词表

filter(**kwargs): 返回符合筛选条件的数据集

exclude(**kwargs):   返回不符合筛选条件的数据集

Comment.objects.filter(pub_date__year=2015)

多个filter和exclude可以链接在一起查询

Comment.objects.filter(pub_date__year=2015).exclude(pub_date__month=1).exclude(n_visits__exact=0)

get() :查询单条记录,注意没有查询到数据的时候会报错  

Comment.objects.get(id_exact=1)

all():  查询所有数据

Comment.objects.all()
Comment.objects.all()[:10]
Comment.objects.all[10:20]

order_by():   排序

Comment.objects.order_by('headline')

  

  

  

  

posted @ 2017-10-26 23:01  Wang-Vee  阅读(250)  评论(0编辑  收藏  举报