嗨,我正在尝试添加一个过滤器并排除到我的查询集中,但是不知道如何。我可以分别过滤和排除,但不能同时进行。
这是我的解析器
def resolve_articles(self, info, limit=None, offset=None, slug=None, search=None, exclude=None, braking=None, non_braking=None):
if search:
filter = (
Q(id__icontains=search) |
Q(title__icontains=search) |
Q(categories__name__icontains=search)
)
return BlogPage.objects.filter(filter).order_by('-first_published_at')[offset:limit]
我该怎么做
def resolve_articles(self, info, limit=None, offset=None, slug=None, search=None, exclude=None, braking=None, non_braking=None):
if search and exclude:
filter = (
Q(id__icontains=search) and
Q(categories__name__icontains=exclude)
)
return BlogPage.objects.filter(filter).exclude(filter).order_by('-first_published_at')[offset:limit]
谢谢