Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #708 -- Fixed searching within IP fields on PostgreSQL.

Based on a patch from Matt McClanahan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7151 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6482f1f8877638493810d2740c56e1b62519c8bd 1 parent 3240277
Malcolm Tredinnick authored February 23, 2008
5  django/db/backends/postgresql/operations.py
@@ -27,6 +27,11 @@ def date_trunc_sql(self, lookup_type, field_name):
27 27
     def deferrable_sql(self):
28 28
         return " DEFERRABLE INITIALLY DEFERRED"
29 29
 
  30
+    def field_cast_sql(self, db_type):
  31
+        if db_type == 'inet':
  32
+            return 'CAST(%s AS TEXT)'
  33
+        return '%s'
  34
+
30 35
     def last_insert_id(self, cursor, table_name, pk_name):
31 36
         cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
32 37
         return cursor.fetchone()[0]
8  tests/regressiontests/string_lookup/models.py
@@ -39,6 +39,7 @@ def __unicode__(self):
39 39
 class Article(models.Model):
40 40
     name = models.CharField(max_length=50)
41 41
     text = models.TextField()
  42
+    submitted_from = models.IPAddressField(blank=True, null=True)
42 43
 
43 44
     def __str__(self):
44 45
         return "Article %s" % self.name
@@ -98,4 +99,11 @@ def __str__(self):
98 99
 
99 100
 >>> Article.objects.get(text__contains='quick brown fox')
100 101
 <Article: Article Test>
  102
+
  103
+# Regression test for #708: "like" queries on IP address fields require casting
  104
+# to text (on PostgreSQL).
  105
+>>> Article(name='IP test', text='The body', submitted_from='192.0.2.100').save()
  106
+>>> Article.objects.filter(submitted_from__contains='192.0.2')
  107
+[<Article: Article IP test>]
  108
+
101 109
 """}

0 notes on commit 6482f1f

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