def filter_not(self, *arguments, **kwargs): from motorengine.query_builder.node import Q, QCombination, QNot if arguments and len(arguments) == 1 and isinstance( arguments[0], (Q, QCombination)): self.filter(QNot(arguments[0])) else: self.filter(QNot(Q(**kwargs))) return self
def filter_not(self, *arguments, **kwargs): ''' Filters a queryset to negate all the filters passed in subsequent queries. Usage:: User.objects.filter_not(first_name="Bernardo").filter_not(last_name="Bernardo").find_all(callback=handle_all) # or User.objects.filter_not(first_name="Bernardo", starting_year__gt=2010).find_all(callback=handle_all) The available filter options are the same as used in MongoEngine. ''' from motorengine.query_builder.node import Q, QCombination, QNot if arguments and len(arguments) == 1 and isinstance(arguments[0], (Q, QCombination)): self.filter(QNot(arguments[0])) else: self.filter(QNot(Q(**kwargs))) return self