Skip to content

Commit 24533b0

Browse files
author
Jay Deiman
committed
Added fixes for compatibility with django 1.2
1 parent 4ce3d32 commit 24533b0

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

netfields/managers.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from IPy import IP
22

3+
from types import StringTypes
34
from django.db import models, connection
45
from django.db.models import sql, query
56
from django.db.models.query_utils import QueryWrapper
@@ -33,19 +34,26 @@ def add_filter(self, (filter_string, value), *args, **kwargs):
3334

3435

3536
class NetWhere(sql.where.WhereNode):
36-
def make_atom(self, child, qn):
37-
table_alias, name, db_type, lookup_type, value_annot, params = child
37+
def make_atom(self, child, qn , conn):
38+
if isinstance(child[0] , sql.where.Constraint):
39+
c = child[0]
40+
table_alias = c.alias
41+
name = c.col
42+
field = c.field
43+
lookup_type , value_annot , params = child[1:]
44+
else:
45+
table_alias, name, db_type, lookup_type, value_annot, params = child
3846

39-
if db_type not in ['inet', 'cidr']:
40-
return super(NetWhere, self).make_atom(child, qn)
47+
if field.db_type() not in ['inet', 'cidr']:
48+
return super(NetWhere, self).make_atom(child, qn , conn)
4149

4250
if table_alias:
4351
field_sql = '%s.%s' % (qn(table_alias), qn(name))
4452
else:
4553
field_sql = qn(name)
4654

4755
if NET_OPERATORS.get(lookup_type, '') in NET_TEXT_OPERATORS:
48-
if db_type == 'inet':
56+
if field.db_type() == 'inet':
4957
field_sql = 'HOST(%s)' % field_sql
5058
else:
5159
field_sql = 'TEXT(%s)' % field_sql
@@ -55,6 +63,9 @@ def make_atom(self, child, qn):
5563
else:
5664
extra = ''
5765

66+
if type(params) in StringTypes:
67+
params = (params,)
68+
5869
if lookup_type in NET_OPERATORS:
5970
return (' '.join([field_sql, NET_OPERATORS[lookup_type], extra]), params)
6071
elif lookup_type == 'in':
@@ -71,9 +82,9 @@ def make_atom(self, child, qn):
7182
raise ValueError('Invalid lookup type "%s"' % lookup_type)
7283

7384

74-
class NetManger(models.Manager):
85+
class NetManager(models.Manager):
7586
use_for_related_fields = True
7687

7788
def get_query_set(self):
78-
q = NetQuery(self.model, connection, NetWhere)
89+
q = NetQuery(self.model, NetWhere)
7990
return query.QuerySet(self.model, q)

0 commit comments

Comments
 (0)