Skip to content

Instantly share code, notes, and snippets.

@vinaychittora
Created January 31, 2014 10:30
Show Gist options
  • Save vinaychittora/8729752 to your computer and use it in GitHub Desktop.
Save vinaychittora/8729752 to your computer and use it in GitHub Desktop.
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