django-ajax-forms icon indicating copy to clipboard operation
django-ajax-forms copied to clipboard

date json serializable error

Open interprogs opened this issue 11 years ago • 0 comments

Hi,

When you use Modelform and you have (auto_now_add=True) you have this error: TypeError: datetime.datetime(2013, 12, 4, 17, 23, 51, 893632, tzinfo=<UTC>) is not JSON serializable

For correct this:

add :

from django.core.serializers.json import DjangoJSONEncoder
import json

and change in views.py:

def convert_context_to_json(self, context):
        return json.dumps(context, cls=DjangoJSONEncoder)

also like that deprecated use of simplejson is corrected.

(source from http://stackoverflow.com/a/5781657)

interprogs avatar Dec 04 '13 17:12 interprogs