﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23549	Model form's model_to_dict using value_from_object instead of to_python	mwaterfall	nobody	"Background: I'm using a [https://github.com/bradjasper/django-jsonfield/ JSONField] model field to store a list of strings in a field, and I'm trying to create a model form with a series of checkboxes that allows me to multiple select zero or more of these string options using `TypedMultipleChoiceField` and `CheckboxSelectMultiple`.

Issue: When the form is rendered, the checkboxes that should be checked aren't checked. When saving the form, the checked values are correctly saved and serialised by the field.

Cause:

The reason the checkboxes aren't getting checked is down to the function `model_to_dict`, that converts a model instance to a dict ready to populate a ModelForm. The value is retrieved from instance fields using `value_from_object`. Why is `to_python` not used? 

The JSONField is following the guidelines to create a custom model field, overriding the `to_python` to deserialise the raw value from the DB and return a python object. This `model_to_dict` is bypassing this, not allowing custom fields to deserialise values before they are used to populate a form.

Hence the form is receiving the JSON string as opposed to the deserialised list, and causing things to be rendered incorrectly.

Here's the line in question: https://github.com/django/django/blob/1.7/django/forms/models.py#L151"	Bug	closed	Forms	1.7	Normal	invalid	form, modelform, field	M. Shafiq	Unreviewed	0	0	0	0	0	0
