diff options
| author | Jason Myers <jason@jasonamyers.com> | 2013-11-03 07:19:25 -0600 |
|---|---|---|
| committer | Jason Myers <jason@jasonamyers.com> | 2013-11-03 07:19:25 -0600 |
| commit | 4f151da1e5e9bf527548a5737d9cd314e3abc68e (patch) | |
| tree | 6ba849758c7c34cdf593ad6e699ad420b7ce57c1 /django/forms | |
| parent | 6f070273856720b1192af534f37622a9c42525b9 (diff) | |
| parent | f40f90d63b4be295269b5f0de5f919be22daba5c (diff) | |
Merging in master
Signed-off-by: Jason Myers <jason@jasonamyers.com>
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/models.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 71da43390c..32f0f043ae 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -134,7 +134,11 @@ def model_to_dict(instance, fields=None, exclude=None): data[f.name] = [] else: # MultipleChoiceWidget needs a list of pks, not object instances. - data[f.name] = list(f.value_from_object(instance).values_list('pk', flat=True)) + qs = f.value_from_object(instance) + if qs._result_cache is not None: + data[f.name] = [item.pk for item in qs] + else: + data[f.name] = list(qs.values_list('pk', flat=True)) else: data[f.name] = f.value_from_object(instance) return data |
