diff options
author | Andrey Kuzmin <jack.cvr@gmail.com> | 2015-10-23 05:29:46 +0300 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-10-23 16:23:30 -0400 |
commit | a1b9737aeaed4e218e264369e2f6591c8c03aafd (patch) | |
tree | cd68c18a3baa3bc7f3c3818e6180a95c0baeeebe /django/core/serializers/python.py | |
parent | 10ace52a41fc3458fb7df51d11974b398f0fbde3 (diff) | |
download | django-a1b9737aeaed4e218e264369e2f6591c8c03aafd.tar.gz |
Cached model field_names in Python Deserializer.
Diffstat (limited to 'django/core/serializers/python.py')
-rw-r--r-- | django/core/serializers/python.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index b64169bb62..09a5438861 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -89,6 +89,7 @@ def Deserializer(object_list, **options): """ db = options.pop('using', DEFAULT_DB_ALIAS) ignore = options.pop('ignorenonexistent', False) + field_names_cache = {} # Model: <list of field_names> for d in object_list: # Look up the model and starting build a dict of data for it. @@ -106,7 +107,10 @@ def Deserializer(object_list, **options): except Exception as e: raise base.DeserializationError.WithData(e, d['model'], d.get('pk'), None) m2m_data = {} - field_names = {f.name for f in Model._meta.get_fields()} + + if Model not in field_names_cache: + field_names_cache[Model] = {f.name for f in Model._meta.get_fields()} + field_names = field_names_cache[Model] # Handle each field for (field_name, field_value) in six.iteritems(d["fields"]): |