@@ -101,6 +101,7 @@ def get_operator(self, operator):
101101 '<' : '__lt' ,
102102 '<=' : '__lte' ,
103103 '~' : '__icontains' ,
104+ 'regex' : '__iregex' ,
104105 'in' : '__in' ,
105106 }.get (operator )
106107 if op is not None :
@@ -124,11 +125,12 @@ def get_lookup(self, path, operator, value):
124125 be ['author', 'groups']. 'name' is not included, because it's the
125126 current field instance itself.
126127 :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.
132134 :param value: value passed for comparison
133135 :return: Q-object
134136 """
@@ -277,7 +279,7 @@ def get_lookup(self, path, operator, value):
277279 # and resulting comparison would look like
278280 # 'created LIKE %2017-01-30 00:00:00%'
279281 # 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 )
281283
282284 q = models .Q (** {'%s%s' % (search , op ): val })
283285 return ~ q if invert else q
0 commit comments