如何解决如何使用graphene-django和django-filters在django中创建“不等于”和“不在”过滤器
我试图找到有关如何执行 not equal
和 not in
过滤的解决方案,但由于我缺乏经验,我无法确定解决方案。
这是我当前结构的一个片段。
# result/models.py
class Result(models.Model):
...
object = models.ForeignKey(Object,on_delete=models.PROTECT)
...
# result/types.py
class ResultType(DjangoObjectType):
class Meta:
model = Result
filter_fields = {
...
'object__object_name': ['exact','icontains'],...
}
convert_choices_to_enum = False
interfaces = (graphene.relay.Node,)
object = DjangoFilterConnectionField(ObjectType)
# result/queries.py
class Query(object):
results = DjangoFilterConnectionField(ResultType)
我希望能够执行类似于以下内容的搜索:
# result/types.py
class ResultType(DjangoObjectType):
class Meta:
model = Result
filter_fields = {
...
'object__object_name': ['exact','icontains','notequal','notin'],...
}
convert_choices_to_enum = False
interfaces = (graphene.relay.Node,)
object = DjangoFilterConnectionField(ObjectType)
因此您可以执行下面的查询,就像 not equal
和 not in
一样。
query {
results ( object_ObjectName__Notequal: "Pluto"){
edges {
node {
object {
objectName
}
}
}
}
}
更新 (2021-03-18):已解决
用户 tcleonard
向我展示了达到此结果的方法。
https://github.com/graphql-python/graphene-django/issues/1145
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。