object.filter()

querySet.distinct() 去重復(fù)

__exact 精確等于 like 'aaa'

__iexact 精確等于 忽略大小寫 ilike 'aaa'

__contains 包含 like '%aaa%'

__icontains 包含 忽略大小寫 ilike '%aaa%',但是對(duì)于sqlite來說,contains的作用效果等同于icontains。

__gt 大于

__gte 大于等于

__lt 小于

__lte 小于等于

__in 存在于一個(gè)list范圍內(nèi)

__startswith 以...開頭

__istartswith 以...開頭 忽略大小寫

__endswith 以...結(jié)尾

__iendswith 以...結(jié)尾,忽略大小寫

__range 在...范圍內(nèi)

__year 日期字段的年份

__month 日期字段的月份

__day 日期字段的日

__isnull=True/False

ex:

def get_queryset(self):

""" Return the last five published questions (not including those set to be published in the future). """

????????returnQuestion.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]

注:pub_date 是Question某個(gè)field

explanation:

Question.objects.filter(pub_date__lte=timezone.now())?returns a queryset containing?Questions whose?pub_date?is less than or equal to - that is, earlier than or equal to -?timezone.now.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容