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 MultiQuerySet(object): | |
def __init__(self, *args, **kwargs): | |
self.querysets = args | |
self._count = None | |
def count(self): | |
if not self._count: | |
self._count = sum(len(qs) for qs in self.querysets) | |
return self._count | |
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
from django.db.models import Q | |
from django.utils.text import smart_split | |
def get_or_query(query_string, fields): | |
return reduce(Q.__or__, | |
(Q(**{'%s__iregex' % field: r"[[:<:]]%s" % term.strip('\'"')}) | |
for term in smart_split(query_string) if term not in ['and', 'or'] | |
for field in fields), | |
Q()) |