Alex Rivera | Logout

How do you serialize a model instance in Django?

Asked 2009-04-16T16:47:31.717
233

There is a lot of documentation on how to serialize a Model QuerySet but how do you just serialize to JSON the fields of a Model Instance?

Edit
Report

1 Answer

1

how about this way:

def ins2dic(obj):
    SubDic = obj.__dict__
    del SubDic['id']
    del SubDic['_state']
return SubDic

or exclude anything you don't want.

answered 2011-06-22T05:11:07.050

Your Answer