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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user