Author: mtredinnick
Date: 2008-02-23 03:15:35 -0600 (Sat, 23 Feb 2008)
New Revision: 7151

Modified:
   django/trunk/django/db/backends/postgresql/operations.py
   django/trunk/tests/regressiontests/string_lookup/models.py
Log:
Fixed #708 -- Fixed searching within IP fields on PostgreSQL.
Based on a patch from Matt McClanahan.


Modified: django/trunk/django/db/backends/postgresql/operations.py
===================================================================
--- django/trunk/django/db/backends/postgresql/operations.py    2008-02-23 
08:36:41 UTC (rev 7150)
+++ django/trunk/django/db/backends/postgresql/operations.py    2008-02-23 
09:15:35 UTC (rev 7151)
@@ -27,6 +27,11 @@
     def deferrable_sql(self):
         return " DEFERRABLE INITIALLY DEFERRED"
 
+    def field_cast_sql(self, db_type):
+        if db_type == 'inet':
+            return 'CAST(%s AS TEXT)'
+        return '%s'
+
     def last_insert_id(self, cursor, table_name, pk_name):
         cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, 
pk_name))
         return cursor.fetchone()[0]

Modified: django/trunk/tests/regressiontests/string_lookup/models.py
===================================================================
--- django/trunk/tests/regressiontests/string_lookup/models.py  2008-02-23 
08:36:41 UTC (rev 7150)
+++ django/trunk/tests/regressiontests/string_lookup/models.py  2008-02-23 
09:15:35 UTC (rev 7151)
@@ -39,6 +39,7 @@
 class Article(models.Model):
     name = models.CharField(max_length=50)
     text = models.TextField()
+    submitted_from = models.IPAddressField(blank=True, null=True)
 
     def __str__(self):
         return "Article %s" % self.name
@@ -98,4 +99,11 @@
 
 >>> Article.objects.get(text__contains='quick brown fox')
 <Article: Article Test>
+
+# Regression test for #708: "like" queries on IP address fields require casting
+# to text (on PostgreSQL).
+>>> Article(name='IP test', text='The body', 
submitted_from='192.0.2.100').save()
+>>> Article.objects.filter(submitted_from__contains='192.0.2')
+[<Article: Article IP test>]
+
 """}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to