Skip to content

Commit

Permalink
Fixed #708 -- Fixed searching within IP fields on PostgreSQL.
Browse files Browse the repository at this point in the history
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
malcolmt committed Feb 23, 2008
1 parent 3240277 commit 6482f1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions django/db/backends/postgresql/operations.py
Expand Up @@ -27,6 +27,11 @@ def date_trunc_sql(self, lookup_type, field_name):
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]
Expand Down
8 changes: 8 additions & 0 deletions tests/regressiontests/string_lookup/models.py
Expand Up @@ -39,6 +39,7 @@ def __unicode__(self):
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
Expand Down Expand Up @@ -98,4 +99,11 @@ def __str__(self):
>>> 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>]
"""}

0 comments on commit 6482f1f

Please sign in to comment.