summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-06-09 14:03:35 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-06-09 14:03:35 +0000
commit12716794dbcf2e1bf7a07bd18dfc0ae24be4e6f8 (patch)
treeebeae5a3a44e340afd6def0479c44b58d2548232 /django
parent1426c2451756572fccaf264ed2b752553b1c7933 (diff)
Fixed #7350, #7202 -- Fixed serialization for multi-model inheritance, which had multiple problems:
* Serializers were including all superclass fields in their output. Now only local fields are included. * Implicit OneToOne primary keys were not correctly added to the metamodel, so they were always marked to be serialized, even though they were primary * Model saving was too aggressive about creating new parent class instances during deserialization. Raw save on a model now skips saving of the parent class. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7600 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/serializers/base.py2
-rw-r--r--django/db/models/base.py13
-rw-r--r--django/db/models/options.py2
3 files changed, 11 insertions, 6 deletions
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index a79497ecec..e22a35815b 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -38,7 +38,7 @@ class Serializer(object):
self.start_serialization()
for obj in queryset:
self.start_object(obj)
- for field in obj._meta.fields:
+ for field in obj._meta.local_fields:
if field.serialize:
if field.rel is None:
if self.selected_fields is None or field.attname in self.selected_fields:
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 0ee225675a..5dd11a9d83 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -290,12 +290,17 @@ class Model(object):
meta = cls._meta
signal = False
- for parent, field in meta.parents.items():
- self.save_base(raw, parent)
- setattr(self, field.attname, self._get_pk_val(parent._meta))
+ # If we are in a raw save, save the object exactly as presented.
+ # That means that we don't try to be smart about saving attributes
+ # that might have come from the parent class - we just save the
+ # attributes we have been given to the class we have been given.
+ if not raw:
+ for parent, field in meta.parents.items():
+ self.save_base(raw, parent)
+ setattr(self, field.attname, self._get_pk_val(parent._meta))
non_pks = [f for f in meta.local_fields if not f.primary_key]
-
+
# First, try an UPDATE. If that doesn't update anything, do an INSERT.
pk_val = self._get_pk_val(meta)
# Note: the comparison with '' is required for compatibility with
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 4036bfb36e..bc1aec62c1 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -102,7 +102,7 @@ class Options(object):
# field.
field = self.parents.value_for_index(0)
field.primary_key = True
- self.pk = field
+ self.setup_pk(field)
else:
auto = AutoField(verbose_name='ID', primary_key=True,
auto_created=True)