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')
相關文章
相關標籤/搜索