Opened 12 years ago
Closed 12 years ago
#21700 closed Bug (wontfix)
model_to_dict return id key as unicode
| Reported by: | 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 , 12 years ago
| Component: | Database layer (models, ORM) → Forms |
|---|---|
| Easy pickings: | unset |
| Resolution: | → wontfix |
| Status: | new → closed |
| Version: | 1.6 → master |
Note:
See TracTickets
for help on using tickets.
Since
model_to_dictis a private API (It has not been documented) and Django doesn't internally requires amodel->namedtupleserializer nor is affected by theunicodekeys 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_dictis 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_namedtuplefor your specific needs.