question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

model_to_dict with DateField

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alexpantyukhincommented, Mar 12, 2016

Sorry. found the reason it was another

1reaction
rennerochacommented, Mar 31, 2016

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django model_to_dict skips all DateTimeField when ...
I just noticed a bug with model_to_dict that it skips all DateTimeField in the model and never convert them to the dictionary, whereas...
Read more >
Django model_to_dict and Missing Fields - Metal Toad
Background. I had a Django Model that looked something like this: class MyModel(models.Model): date_added = models.DateTimeField('date ...
Read more >
django.db.models DateField Example Code - Full Stack Python
Python code examples for the DateField class used in the Django ORM, found within the django.db.models module of the Django project.
Read more >
DateField - Django Models - GeeksforGeeks
DateField is a field that stores date, represented in Python by a datetime.date instance. As the name suggests, this field is used to...
Read more >
Django model_to_dict skips all DateTimeField ... - YouTube
Django : Django model_to_dict skips all DateTimeField when converting models [ Beautify Your Computer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found