【问题标题】:Filter not null dates with Django and GraphQL使用 Django 和 GraphQL 过滤非空日期
【发布时间】:2021-04-05 08:39:04
【问题描述】:

我们有一个带有feauted_date (DateTime) 字段的游览节点,它也可以为空。

class TourFilter(OrderByMixin):
    class Meta:
        model = TourModel
        fields = {
            'featured_date': ['exact', 'lt', 'gt'],
        }

class TourNode(DjangoObjectType):
    class Meta:
        model = TourModel
        filter_fields = TourFilter.Meta.fields
        interfaces = (relay.Node, )

目前我们使用featured_dateOrderMixin 进行排序,但是有没有办法通过非空来过滤它们?

【问题讨论】:

    标签: django graphql graphene-python graphene-django


    【解决方案1】:

    您可以使用isnull-(doc) 查找

    class TourFilter(OrderByMixin):
        class Meta:
            model = TourModel
            fields = {
                'featured_date': ['exact', 'lt', 'gt', 'isnull'],
            }

    【讨论】:

    • 谢谢!这正是我一直在寻找的。​​span>
    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 2011-11-16
    • 2023-03-23
    • 2011-07-11
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 2020-07-21
    相关资源
    最近更新 更多