model_to_dict with DateField
See original GitHub issueHi! 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:
- Created 8 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry. found the reason it was another
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!