diff options
Diffstat (limited to 'django/core/serializers/python.py')
| -rw-r--r-- | django/core/serializers/python.py | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 839fee12a9..a68ea21f78 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -27,13 +27,11 @@ class Serializer(base.Serializer): self._current = {} def end_object(self, obj): - data = { - "model": smart_unicode(obj._meta), - "fields": self._current - } - if not self.use_natural_keys or not hasattr(obj, 'natural_key'): - data['pk'] = smart_unicode(obj._get_pk_val(), strings_only=True) - self.objects.append(data) + self.objects.append({ + "model" : smart_unicode(obj._meta), + "pk" : smart_unicode(obj._get_pk_val(), strings_only=True), + "fields" : self._current + }) self._current = None def handle_field(self, obj, field): @@ -84,9 +82,7 @@ def Deserializer(object_list, **options): for d in object_list: # Look up the model and starting build a dict of data for it. Model = _get_model(d["model"]) - data = {} - if 'pk' in d: - data[Model._meta.pk.attname] = Model._meta.pk.to_python(d['pk']) + data = {Model._meta.pk.attname : Model._meta.pk.to_python(d["pk"])} m2m_data = {} # Handle each field @@ -131,9 +127,7 @@ def Deserializer(object_list, **options): else: data[field.name] = field.to_python(field_value) - obj = base.build_instance(Model, data, db) - - yield base.DeserializedObject(obj, m2m_data) + yield base.DeserializedObject(Model(**data), m2m_data) def _get_model(model_identifier): """ |
