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)
    

      


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

  • 相关阅读:
    distcc加速内核编译
    ssh不检查server变化
    bbb u-boot SPI 启动
    Debian NAT共享上网
    Debian Epson L455 打印机
    Learn CMake's Scripting Language in 15 Minutes (ZZ)
    网络启动并安装Debian
    GNU LD 脚本学习笔记
    JLink defective
    获取真实mac地址
  • 原文地址:https://www.cnblogs.com/AngryZe/p/9263684.html
Copyright © 2011-2022 走看看