Re-enable substring lookups for IP address fields in Postgres using HOST() Thanks for the suggestion, Thomas Adamcik. Fixes #708.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7161 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f7fbc289ad
commit
a9b4efc82b
|
@ -27,6 +27,11 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def deferrable_sql(self):
|
def deferrable_sql(self):
|
||||||
return " DEFERRABLE INITIALLY DEFERRED"
|
return " DEFERRABLE INITIALLY DEFERRED"
|
||||||
|
|
||||||
|
def field_cast_sql(self, db_type):
|
||||||
|
if db_type == 'inet':
|
||||||
|
return 'HOST(%s)'
|
||||||
|
return '%s'
|
||||||
|
|
||||||
def last_insert_id(self, cursor, table_name, pk_name):
|
def last_insert_id(self, cursor, table_name, pk_name):
|
||||||
cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
|
cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
|
|
@ -39,6 +39,7 @@ class Base(models.Model):
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
|
submitted_from = models.IPAddressField(blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Article %s" % self.name
|
return "Article %s" % self.name
|
||||||
|
@ -98,4 +99,11 @@ __test__ = {'API_TESTS': ur"""
|
||||||
|
|
||||||
>>> Article.objects.get(text__contains='quick brown fox')
|
>>> Article.objects.get(text__contains='quick brown fox')
|
||||||
<Article: Article Test>
|
<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>]
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue