python - 如何使用 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
解决方案
推荐阅读
- python - 如何解决“ImportError:没有名为 google.auth 的模块”?
- powershell - 如何使用 Powershell 扫描三星扫描仪/打印机
- python-3.x - SAS to Python中的Retain Statement、Groupby和IF条件
- python - 将递归 POST 数据转换为 JSON 对象
- c++ - 运行时带有参数的 Qt 控制台应用程序
- apache-camel - Apache Camel 解压、处理和聚合未完成
- asp.net - Asp.Net Web Api 允许 Url 编码的正向/反向斜杠
- django - 如何创建一个在同一页面上显示所有单选按钮的表单?
- r - 未提供错误行号时如何调试?
- mysql - MySQL GROUP BY 跨三个表的空间搜索速度慢