Skip to content

Commit a278f34

Browse files
committedFeb 10, 2011
Use same procedure as django for expansion of child in make_atom
1 parent db8d423 commit a278f34

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
 

‎netfields/managers.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ def add_filter(self, (filter_string, value), *args, **kwargs):
3434

3535
class NetWhere(sql.where.WhereNode):
3636
def make_atom(self, child, qn, conn):
37-
if isinstance(child[0], sql.where.Constraint):
38-
c = child[0]
39-
table_alias = c.alias
40-
name = c.col
41-
field = c.field
42-
lookup_type, value_annot, params = child[1:]
37+
lvalue, lookup_type, value_annot, params_or_value = child
38+
39+
if hasattr(lvalue, 'process'):
40+
try:
41+
lvalue, params = lvalue.process(lookup_type, params_or_value, connection)
42+
except EmptyShortCircuit:
43+
raise EmptyResultSet
4344
else:
44-
table_alias, name, db_type, lookup_type, value_annot, params = child
45+
return super(NetWhere, self).make_atom(child, qn, conn)
46+
47+
table_alias, name, db_type = lvalue
4548

46-
if field.db_type() not in ['inet', 'cidr']:
49+
if db_type not in ['inet', 'cidr']:
4750
return super(NetWhere, self).make_atom(child, qn, conn)
4851

4952
if table_alias:
@@ -52,7 +55,7 @@ def make_atom(self, child, qn, conn):
5255
field_sql = qn(name)
5356

5457
if NET_OPERATORS.get(lookup_type, '') in NET_TEXT_OPERATORS:
55-
if field.db_type() == 'inet':
58+
if db_type == 'inet':
5659
field_sql = 'HOST(%s)' % field_sql
5760
else:
5861
field_sql = 'TEXT(%s)' % field_sql

0 commit comments

Comments
 (0)