summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnton I. Sipos <aisipos@gmail.com>2012-11-04 15:42:17 -0800
committerAnton I. Sipos <aisipos@gmail.com>2012-11-04 15:52:05 -0800
commite44ab5bb4fd3aa826ca4243a8ea9fd7125800da2 (patch)
tree8882072ce524d389d2f41aec78835e9037fbc6b2 /django
parent8d3f932f18c75fcbb32cf3dd5998445d65b5db0f (diff)
Fixed #18949 -- Improve performance of model_to_dict with many-to-many
When calling model_to_dict, improve performance of the generated SQL by using values_list to determine primary keys of many to many objects. Add a specific test for this function, test_model_to_dict_many_to_many Thanks to brian for the original report and suggested fix.
Diffstat (limited to 'django')
-rw-r--r--django/forms/models.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 11fe0c09ea..e9b71ccf26 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -126,7 +126,7 @@ 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] = [obj.pk for obj in f.value_from_object(instance)]
+ data[f.name] = list(f.value_from_object(instance).values_list('pk', flat=True))
else:
data[f.name] = f.value_from_object(instance)
return data