Django 字段查询谓词表

it2022-05-18  64

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')

  

  

  

  

转载于:https://www.cnblogs.com/Vee-Wang/p/7740067.html

相关资源:数据结构—成绩单生成器

最新回复(0)