2
why a simple result.filter(Q(somedbfield_icontains=q)) returns and error
The simplest variant would be result.filter(somedbfield__icontains=q)
Q isnβt needed there, Q is used to extend your filtering with logic operators (and, or, not). Also, notice the double underscore before icontains
.
why reduce needs to get bitwise value?
reduce
is used to apply any function to an iterable of arguments:
operator.add(1, 2)
is the same as 1 + 2
reduce(operator.add, (1, 2, 3, 4, 5))
is the same as ((((1 + 2) + 3) + 4) + 5)
Works roughly like this:
def reduce(function, iterable):
it = iter(iterable)
value = next(it)
for element in it:
value = function(value, element)
return value
Source:stackexchange.com