Peewee: model_to_dict with DateField

Created on 12 Mar 2016  路  5Comments  路  Source: coleifer/peewee

Hi!
I have such model:

class User(BaseModel, UserMixin):
    birth_date = DateField(null=True)
    ......

And when I try to do this:

model_to_dict(current_user)

I'm getting this error:
TypeError: datetime.date(1989, 8, 9) is not JSON serializable

All 5 comments

But model_to_dict doesn't do any json serialization?

Sorry. found the reason it was another

alexpantyukhin , what was the reason? I am having the same problem.

model_to_dict returns a dict, not a JSON object, so I'm not sure what the confusion is about.

Sorry, model_to_dict is working as expected. I am making a confusion here.
I am trying to use json.dumps in a dictionary returned by model_to_dict, and it is failing (as expected).
The solution is not related to peewee code.
Sorry for this unnecessary message!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexlatchford picture alexlatchford  路  4Comments

vkrizan picture vkrizan  路  3Comments

hanxifu picture hanxifu  路  4Comments

mikemill picture mikemill  路  3Comments

ghost picture ghost  路  5Comments