zoukankan      html  css  js  c++  java
  • [Django学习] Django基础(6)_Field lookups

    一. 常见的三个函数

      1. filter

      2. exclude

      3. get

      4. dates(field, kind, order=’ASC’)

        (1) field should be the name of a DateField of your model.

        (2) kind should be either "year", "month" or "day". Each datetime.date object in the result list is “truncated” to the given type.

          • "year" returns a list of all distinct year values for the field.

          • "month" returns a list of all distinct year/month values for the field.

          • "day" returns a list of all distinct year/month/day values for the field.

        (3)order, which defaults to ’ASC’, should be either ’ASC’ or ’DESC’. This specifies how to order the results. 

    二. 常见的查询方式

    方式名 大小写敏感 说明
    exact 等于
    iexact

    contain

    包含
    icontain
    in 成员
    range 范围
    gt 大于
    gte 大于等于
    lt 小于
    lte 小于等于
    startswith 以...开始
    istartswith
    endswith 以...结尾
    istartswith

    year,month,day,week_day,hour,minute,second

    时间
    isnull 为空
    regex 正则表达式
    iregex

    三. 双下划线(__)的作用

      1.字段查询类型:field__lookuptype=value   

    # 查询Blog中create_time < somedate的所有数据
    Blog.objects.filter(create_time__lt=somedate)  

      2.外键的扩展:

      3.日期的扩展:   

    # 查询Blog中create_time.year = someyear的数据
    Blog.objects.filter(create_time__year=someyear)  

      4.链式查询:

    #查询Blog中create_time.year < someyear的所有数据
    Blog.objects.filter(create_time__year__lt=someyear)
    

      


    注明:学习资料来自“再敲一行代码的个人空间”以及“杨仕航的博客”

  • 相关阅读:
    SSH的密钥登录配置
    VMware 15pro虚拟机网络设置
    12种SQL注入报错方式
    PHP myadmin 无路径getshell
    MySQL数据库基本操作
    ubuntu 16.04安装后的简单优化
    无聊中,静思自己。
    Silverlight 4.0+Linq to sql 网站后台登陆功能(一)
    AspNetPager和Linq to sql 的完美结合
    Linq to sql 的DataContext 持久化层写法
  • 原文地址:https://www.cnblogs.com/AngryZe/p/9263684.html
Copyright © 2011-2022 走看看