Opened 10 years ago

Closed 10 years ago

#21700 closed Bug (wontfix)

model_to_dict return id key as unicode

Reported by: filip.f.novak@… Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords: models, model_to_dict
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello
After converting the model instance using model_to_dict is the key 'id' unicode type (all others are string). It causes a problem when accessing this parameter for further conversion into namedtuple.
Are you thinking about adding a function model_to_namedtuple? Implementation would (after removing the problem of 'id') elementary.

Output example:
{'code': u'B-US', 'pieces_in_package': 10, u'id': 1}

Thx.

Change History (1)

comment:1 by Simon Charette, 10 years ago

Component: Database layer (models, ORM)Forms
Easy pickings: unset
Resolution: wontfix
Status: newclosed
Version: 1.6master

Since model_to_dict is a private API (It has not been documented) and Django doesn't internally requires a model -> namedtuple serializer nor is affected by the unicode keys issue I don't think we're going to fix that.

I'm not saying such a serializer wouldn't be helpful for third party cases but model_to_dict is really just an internal function (that you shouldn't rely on since it might go away) used by model forms.

I'd suggest you write your own implementation of model_to_namedtuple for your specific needs.

Note: See TracTickets for help on using tickets.
Back to Top