3

I want graphene to output normal date/datetime formats. By default it returns this:

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

And I want it to return this:

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

It seems there is no such option in graphene dictionary, but still I want to use graphene_django.DjangoObjectType to use its Meta class, instead rewrite all fields w/ graphene.ObjectType

nrgx
  • 325
  • 3
  • 13

1 Answers1

3

You can overwrite any field with DjangoObjectType. Your code may look like this.

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))

For more details check out the docs

Ijharul Islam
  • 1,429
  • 11
  • 13
  • As I know you can't overwrite ANY field, only related objects or list fields. If it's a field inside Meta.field you cannot overwrite it, at least you don't add it into Meta.field but add field manually – Shil Nevado Jul 26 '22 at 11:08