0

This is my time_now() function

def time_now():
    return timezone.now()

I call it to init created_at filed of my SkyGroupResource with the following way:

def obj_create(self,bundle,**kwargs):

    return super(SkyGroupResource, self).obj_create(bundle, owner_id=bundle.request.user.skyuser, created_at = time_tools.time_now())

In other resource, I have the following field:

group_id = fields.ForeignKey(SkyGroupResource,'group_id',null=False)

when I'm trying to use my second resorce on POST , I'm getting the following error

TypeError: datetime.datetime(2015, 5, 19, 19, 51, 33, 8253, tzinfo=) is not JSON serializable

Any idea ?

SaeX
  • 17,240
  • 16
  • 77
  • 97

1 Answers1

0

You can convert the date to a string first, using e.g. str(datetime.now()).

*Edit: you should have a look at: How to overcome "datetime.datetime not JSON serializable" in python?.

Community
  • 1
  • 1
SaeX
  • 17,240
  • 16
  • 77
  • 97