@@ -101,6 +101,7 @@ def get_operator(self, operator):
101
101
'<' : '__lt' ,
102
102
'<=' : '__lte' ,
103
103
'~' : '__icontains' ,
104
+ 'regex' : '__iregex' ,
104
105
'in' : '__in' ,
105
106
}.get (operator )
106
107
if op is not None :
@@ -124,11 +125,12 @@ def get_lookup(self, path, operator, value):
124
125
be ['author', 'groups']. 'name' is not included, because it's the
125
126
current field instance itself.
126
127
:param operator: a string with comparison operator. It could be one of
127
- the following: '=', '!=', '>', '>=', '<', '<=', '~', '!~', 'in',
128
- 'not in'. Depending on the field type, some operators may be
129
- excluded. '~' and '!~' can be applied to StrField only and aren't
130
- allowed for any other fields. BoolField can't be used with less or
131
- greater operators, '>', '>=', '<' and '<=' are excluded for it.
128
+ the following: '=', '!=', '>', '>=', '<', '<=', '~', '!~', 'regex',
129
+ 'in', 'not in'. Depending on the field type, some operators
130
+ may be excluded. '~' and '!~' can be applied to StrField only and
131
+ aren't allowed for any other fields. BoolField can't be used with
132
+ less or greater operators, '>', '>=', '<' and '<=' are excluded
133
+ for it.
132
134
:param value: value passed for comparison
133
135
:return: Q-object
134
136
"""
@@ -277,7 +279,7 @@ def get_lookup(self, path, operator, value):
277
279
# and resulting comparison would look like
278
280
# 'created LIKE %2017-01-30 00:00:00%'
279
281
# which is not what we want for this case.
280
- val = value if operator in ('~' , '!~' ) else self .get_lookup_value (value )
282
+ val = value if operator in ('~' , '!~' , 'regex' ) else self .get_lookup_value (value )
281
283
282
284
q = models .Q (** {'%s%s' % (search , op ): val })
283
285
return ~ q if invert else q
0 commit comments