[Answered ]-How to convert DateField field while returning a filtered result in DJANGO

1👍

Pass the date object itself:

Activity.objects.create(name="Foo", date_created=date.today())

Is there a way to format the date_created field while querying all instances of the table Activity using .values() below in the views.py.

The format of a non-text objects is an implementation detail, nor is it the task of the database to format this. You should do this in the template, serializer, or view.

Furthermore using .values() is often not a good idea anyway. Django has a DjangoJSONEncoder [Django-doc] that will encode datetime with the ISO-8601 standard.

Leave a comment