gpt4 book ai didi

django - 如何在 Graphite 烯中格式化日期和日期时间

转载 作者:行者123 更新时间:2023-12-05 03:58:18 39 4
gpt4 key购买 nike

我希望 Graphite 烯输出正常的日期/日期时间格式。默认情况下它返回这个:

`"createdAt": "2019-06-11T05:48:11.023255+00:00",`

我希望它返回这个:

`"createdAt": "11.06.2019 11:48:11",`

似乎在 Graphite 烯字典中没有这样的选项,但我仍然想使用 graphene_django.DjangoObjectType 来使用它的 Meta 类,而不是用 graphene.ObjectType

最佳答案

您可以使用 DjangoObjectType 覆盖任何字段。您的代码可能如下所示。

class CustomType(DjangoObjectType):

class Meta:
model = CustomModel


created_at = graphene.String()

def resolve_created_at(self, info):
return str(self.created_at.replace(microsecond=0))

有关更多详细信息,请查看 docs

关于django - 如何在 Graphite 烯中格式化日期和日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58113283/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com