Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for istartswith and iendswith in database API

git-svn-id: http://code.djangoproject.com/svn/django/trunk@207 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 57970663831908e8f1e8bb787b04ac923d123e41 1 parent b617884
Adrian Holovaty authored July 19, 2005
4  django/core/db/backends/mysql.py
@@ -99,7 +99,9 @@ def get_date_trunc_sql(lookup_type, field_name):
99 99
     'lt': '<',
100 100
     'lte': '<=',
101 101
     'startswith': 'LIKE',
102  
-    'endswith': 'LIKE'
  102
+    'endswith': 'LIKE',
  103
+    'istartswith': 'ILIKE',
  104
+    'iendswith': 'ILIKE',
103 105
 }
104 106
 
105 107
 # This dictionary maps Field objects to their associated MySQL column
4  django/core/db/backends/postgresql.py
@@ -93,7 +93,9 @@ def get_date_trunc_sql(lookup_type, field_name):
93 93
     'lt': '<',
94 94
     'lte': '<=',
95 95
     'startswith': 'LIKE',
96  
-    'endswith': 'LIKE'
  96
+    'endswith': 'LIKE',
  97
+    'istartswith': 'ILIKE',
  98
+    'iendswith': 'ILIKE',
97 99
 }
98 100
 
99 101
 # This dictionary maps Field objects to their associated PostgreSQL column
36  docs/db-api.txt
@@ -52,21 +52,29 @@ The DB API supports the following lookup types:
52 52
     ==========  ==============================================================
53 53
     Type        Description
54 54
     ==========  ==============================================================
55  
-    exact       Exact match: ``polls.get_object(id__exact=14)``
  55
+    exact       Exact match: ``polls.get_object(id__exact=14)``.
56 56
     iexact      Case-insensitive exact match:
57 57
                 ``polls.get_list(slug__iexact="foo")`` matches a slug of ``foo``,
58 58
                 ``FOO``, ``fOo``, etc.
59 59
     contains    Case-sensitive containment test:
60 60
                 ``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.
67 69
     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.
70 78
     range       Range test:
71 79
                 ``polls.get_list(pub_date__range=(start_date, end_date))``
72 80
                 returns all polls with a pub_date between ``start_date``
@@ -308,13 +316,13 @@ Creating new objects
308 316
 Creating new objects (i.e. ``INSERT``) is done by creating new instances
309 317
 of objects then calling save() on them::
310 318
 
311  
-    >>> p = polls.Poll(id=None, 
  319
+    >>> p = polls.Poll(id=None,
312 320
     ...                slug="eggs",
313 321
     ...                question="How do you like your eggs?",
314 322
     ...                pub_date=datetime.datetime.now(),
315 323
     ...                expire_date=some_future_date)
316 324
     >>> p.save()
317  
-    
  325
+
318 326
 Calling ``save()`` on an object with an id if ``None`` signifies to
319 327
 Django that the object is new and should be inserted.
320 328
 
@@ -326,7 +334,7 @@ Related objects (i.e. ``Choices``) are created using convience functions::
326 334
     >>> p.add_choice(choice="Poached", votes=0)
327 335
     >>> p.get_choice_count()
328 336
     4
329  
-    
  337
+
330 338
 Each of those ``add_choice`` methods is equivilent to (except obviously much
331 339
 simpler than)::
332 340
 
@@ -335,9 +343,9 @@ simpler than)::
335 343
     ...                  choice="Over easy",
336 344
     ...                  votes=0)
337 345
     >>> c.save()
338  
-    
  346
+
339 347
 Note 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 
  348
+for the ``id`` field, nor do you give a value for the field that stores
341 349
 the relation (``poll_id`` in this case).
342 350
 
343 351
 Deleting objects

0 notes on commit 5797066

Please sign in to comment.
Something went wrong with that request. Please try again.