def range_filter(value, f1, f2):
    q1 = Q(**{f1 + '__isnull': True}) | Q(**{f1 + '__lte': value})
    q2 = Q(**{f2 + '__isnull': True}) | Q(**{f2 + '__gte': value})
    return Q(q1, q2)
Assuming a database model with two fields of same data type named
dataset/ETHPy150Open lsaffre/lino/lino/core/utils.py/range_filter