no need to wrap it in addintional Q()
<pre>
        query = (
            Q(device_info__gt=0) & (
                Q(device_info__ralph_device_id__isnull=True) |
                Q(device_info__ralph_device_id=0)
            ) & (
                Q(barcode__istartswith=q) |
                Q(sn__istartswith=q) |
                Q(model__name__icontains=q)
            )
        )
</pre>