zoukankan      html  css  js  c++  java
  • Django 模糊查询

    官方文档地址

    https://docs.djangoproject.com/en/1.8/topics/db/queries/#complex-lookups-with-q-objects

    F查询

    contains查询

    Entry.objects.get(headline__contains='Lennon')
    Roughly translates to this SQL:
    SELECT ... WHERE headline LIKE '%Lennon%';

    icontains查询

    q.exclude(body_text__icontains="food")

    exact   查询

    Entry.objects.get(headline__exact="Man bites dog")

    iexact查询
    Blog.objects.get(name__iexact="beatles blog")

    Q查询:

    from django.db.models import Q
    Q(question__startswith='What')
    
    
    Q(question__startswith='Who') | Q(question__startswith='What')
    This is equivalent to the following SQL WHERE clause:
    
    WHERE question LIKE 'Who%' OR question LIKE 'What%'
    
    
    Q(question__startswith='Who') | ~Q(pub_date__year=2005)
    
    
    Poll.objects.get(
        Q(question__startswith='Who'),
        Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
    )
    ... roughly translates into the SQL:
    
    SELECT * from polls WHERE question LIKE 'Who%'
        AND (pub_date = '2005-05-02' OR pub_date = '2005-05-06')
  • 相关阅读:
    迭代器简介
    关于判断对象是否相等的问题
    NIO
    BIO流分类介绍
    servlet简介
    http协议简介
    爬虫常用链接
    http和https协议
    爬虫的合法性研究
    爬虫介绍
  • 原文地址:https://www.cnblogs.com/schangech/p/5630178.html
Copyright © 2011-2022 走看看