querySet.distinct() 去重復
__exact 精確等于 like 'aaa'
__iexact 精確等于 忽略大小寫 ilike 'aaa'
__contains 包含 like '%aaa%'
__icontains 包含 忽略大小寫 ilike '%aaa%',但是對于sqlite來說,contains的作用效果等同于icontains订咸。
__gt 大于
__gte 大于等于
__lt 小于
__lte 小于等于
__in 存在于一個list范圍內(nèi)
__startswith 以...開頭
__istartswith 以...開頭 忽略大小寫
__endswith 以...結尾
__iendswith 以...結尾,忽略大小寫
__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某個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.