Created
January 31, 2014 10:30
-
-
Save vinaychittora/8729752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CPCommonQuerySet(QuerySet, CPCommonMixin): | |
def _filter_or_exclude(self, negate, *args, **kwargs): | |
cust_lookups = [] | |
if kwargs.items(): | |
if kwargs.items()[0][0].endswith('__false'): | |
negate = True | |
cust_lookups = filter(lambda s: s[0].endswith('__false'), kwargs.items()) | |
elif kwargs.items()[0][0].endswith('__true'): | |
negate = False | |
cust_lookups = filter(lambda s: s[0].endswith('__true'), kwargs.items()) | |
for lookup in cust_lookups: | |
kwargs.pop(lookup[0]) | |
lookup_prefix = lookup[0].rsplit('__', 1)[0] | |
kwargs.update({ | |
lookup_prefix + '__regex': '"%s": %s' % (lookup[1], 'false' if negate else 'true'), | |
}) | |
return super(self.__class__, self)._filter_or_exclude(negate, *args, **kwargs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment