datetime - Django model_to_dict skips all DateTimeField when converting models -


i noticed bug model_to_dict skips datetimefield in model , never convert them dictionary, whereas use queryset's values() function not. looked on internet couldn't find else having same problem. want confirm indeed problem other people has encountered , see people solve it. avoid using model_to_dict in case , tries emulate behavior using values()? or there better solution? thoughts?

thanks!

below out:

>>> member = member.objects.get(id=1) >>> member.create_time datetime.datetime(2013, 2, 26, 6, 1, 2, tzinfo=<utc>) >>> model_to_dict(member) {'verified': true, 'name': u'john', 'email': u'', 'phone': u'', 'id': 1l, 'password': u'4e3fc0574fbcdff16c8508339e', 'verify_token': u'5d98aacaba39eb7e'} 

as can see 'create_time' field not in dictionary. had manually insert it:

>>> obj = model_to_dict(member) >>> obj {'verified': true, 'name': u'john', 'email': u'', 'phone': u'', 'id': 1l, 'password': u'4e3fc0574fbcdff16c8508339e', 'verify_token': u'5d98aacaba39eb7e'} >>> obj["create_time"] = member.create_time >>> obj {'verified': true, 'name': u'john', 'email': u'', 'phone': u'', 'create_time': datetime.datetime(2013, 2, 26, 6, 1, 2, tzinfo=<utc>), 'id': 1l, 'password': u'4e3fc0574fbcdff16c8508339e', 'verify_token': u'5d98aacaba39eb7e'} >>> 

edit:

i think found problem: in model_to_dict():

opts = instance._meta f in opts.fields:     if not f.editable:         continue 

and create_time field shown not editable. further research indicates auto_now_add=true automatically make editable=false. causing model_to_dict() skip it...

i found cause auto_now_add=true, automatically sets editable=false, causes model_to_dict() skip fields


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -