1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Merge pull request #495 from aisipos/ticket_18949

Fixed #18949 -- Improve performance of model_to_dict with many-to-many
This commit is contained in:
Alex Gaynor
2012-11-04 15:57:45 -08:00
2 changed files with 37 additions and 1 deletions

View File

@@ -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