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)
    

      


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

  • 相关阅读:
    2.SpringBoot整合Mybatis(一对一)
    1.SpringBoot整合Mybatis(CRUD的实现)
    JavaScript addEventListener()事件监听方法
    jQuery 选择器有61种你都知道了多少
    JavaScript AJAX PHP
    JavaScript BOM Cookie 的用法
    JavaScript Location 对象用法
    JavaScript Date 日期属性和方法
    css3伪类和伪元素你都懂了吗
    css position 5种不同的值的用法
  • 原文地址:https://www.cnblogs.com/AngryZe/p/9263684.html
Copyright © 2011-2022 走看看