Django 字段查询谓词表

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

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

Comment.objects.filter(pub_date__year=2015)

多个filter和exclude能够连接在一块儿查询get

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

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

Comment.objects.get(id_exact=1)

all():  查询全部数据class

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

order_by():   排序object

Comment.objects.order_by('headline')
相关文章
相关标签/搜索