Django

Code

Changeset 207

Show
Ignore:
Timestamp:
07/19/05 10:24:03 (3 years ago)
Author:
adrian
Message:

Added support for istartswith and iendswith in database API

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/db/backends/mysql.py

    r190 r207  
    100100    'lte': '<=', 
    101101    'startswith': 'LIKE', 
    102     'endswith': 'LIKE' 
     102    'endswith': 'LIKE', 
     103    'istartswith': 'ILIKE', 
     104    'iendswith': 'ILIKE', 
    103105} 
    104106 
  • django/trunk/django/core/db/backends/postgresql.py

    r161 r207  
    9494    'lte': '<=', 
    9595    'startswith': 'LIKE', 
    96     'endswith': 'LIKE' 
     96    'endswith': 'LIKE', 
     97    'istartswith': 'ILIKE', 
     98    'iendswith': 'ILIKE', 
    9799} 
    98100 
  • django/trunk/docs/db-api.txt

    r67 r207  
    5353    Type        Description 
    5454    ==========  ============================================================== 
    55     exact       Exact match: ``polls.get_object(id__exact=14)`` 
     55    exact       Exact match: ``polls.get_object(id__exact=14)``. 
    5656    iexact      Case-insensitive exact match: 
    5757                ``polls.get_list(slug__iexact="foo")`` matches a slug of ``foo``, 
     
    5959    contains    Case-sensitive containment test: 
    6060                ``polls.get_list(question__contains="spam")`` returns all polls 
    61                 that contain "spam" in the question. 
    62     icontains   Case-insensitive containment test 
    63     gt          Greater than: ``polls.get_list(id__gt=4)`` 
    64     gte         Greater than or equal to 
    65     lt          Less than 
    66     lte         Less than or equal to 
     61                that contain "spam" in the question. (PostgreSQL only. MySQL 
     62                doesn't support case-sensitive LIKE statements; ``contains`` 
     63                will act like ``icontains`` for MySQL.) 
     64    icontains   Case-insensitive containment test. 
     65    gt          Greater than: ``polls.get_list(id__gt=4)``. 
     66    gte         Greater than or equal to. 
     67    lt          Less than. 
     68    lte         Less than or equal to. 
    6769    startswith  Case-sensitive starts-with: 
    68                 ``polls.get_list(question_startswith="Would")`` 
    69     endswith    Case-sensitive ends-with 
     70                ``polls.get_list(question_startswith="Would")``. (PostgreSQL 
     71                only. MySQL doesn't support case-sensitive LIKE statements; 
     72                ``startswith`` will act like ``istartswith`` for MySQL.) 
     73    endswith    Case-sensitive ends-with. (PostgreSQL only. MySQL doesn't 
     74                support case-sensitive LIKE statements; ``endswith`` will act 
     75                like ``iendswith`` for MySQL.) 
     76    istartswith Case-insensitive starts-with. 
     77    iendswith   Case-insensitive ends-with. 
    7078    range       Range test: 
    7179                ``polls.get_list(pub_date__range=(start_date, end_date))`` 
     
    309317of objects then calling save() on them:: 
    310318 
    311     >>> p = polls.Poll(id=None,  
     319    >>> p = polls.Poll(id=None, 
    312320    ...                slug="eggs", 
    313321    ...                question="How do you like your eggs?", 
     
    315323    ...                expire_date=some_future_date) 
    316324    >>> p.save() 
    317      
     325 
    318326Calling ``save()`` on an object with an id if ``None`` signifies to 
    319327Django that the object is new and should be inserted. 
     
    327335    >>> p.get_choice_count() 
    328336    4 
    329      
     337 
    330338Each of those ``add_choice`` methods is equivilent to (except obviously much 
    331339simpler than):: 
     
    336344    ...                  votes=0) 
    337345    >>> c.save() 
    338      
     346 
    339347Note that when using the `add_foo()`` methods, you do not give any value 
    340 for the ``id`` field, nor do you give a value for the field that stores  
     348for the ``id`` field, nor do you give a value for the field that stores 
    341349the relation (``poll_id`` in this case). 
    342350