[Answered ]-How to use Q objects in Django

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?

It dosen’t

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
πŸ‘€Igonato

Leave a comment