直接使用Q函数即可 group_cond = Q(group__customer__id=customer_id) & ~Q(project_id='') & ~Q(permission__id=25)