From dd441701ced9621f184f8e601339cfb9c16a844b Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sat, 3 Mar 2012 21:34:51 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20#17717=20(again)=20--=20Used=20the=20ne?= =?UTF-8?q?w=20API=20for=20concrete=20models=20added=20in=20r17573.=20Many?= =?UTF-8?q?=20thanks=20to=20Simon=20Charette=20and=20Anssi=20K=C3=A4=C3=A4?= =?UTF-8?q?ri=C3=A4inen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@17643 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/serializers/base.py | 6 +++--- tests/regressiontests/serializers_regress/models.py | 4 ++++ tests/regressiontests/serializers_regress/tests.py | 11 +++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index e4bba1d2409..dbe7787726d 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -43,8 +43,8 @@ class Serializer(object): self.start_object(obj) # Use the concrete parent class' _meta instead of the object's _meta # This is to avoid local_fields problems for proxy models. Refs #17717. - concrete_class = obj._meta.proxy_for_model or obj.__class__ - for field in concrete_class._meta.local_fields: + concrete_model = obj._meta.concrete_model + for field in concrete_model._meta.local_fields: if field.serialize: if field.rel is None: if self.selected_fields is None or field.attname in self.selected_fields: @@ -52,7 +52,7 @@ class Serializer(object): else: if self.selected_fields is None or field.attname[:-3] in self.selected_fields: self.handle_fk_field(obj, field) - for field in concrete_class._meta.many_to_many: + for field in concrete_model._meta.many_to_many: if field.serialize: if self.selected_fields is None or field.attname in self.selected_fields: self.handle_m2m_field(obj, field) diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py index 9381349a610..f366f90806b 100644 --- a/tests/regressiontests/serializers_regress/models.py +++ b/tests/regressiontests/serializers_regress/models.py @@ -263,6 +263,10 @@ class ProxyBaseModel(BaseModel): class Meta: proxy = True +class ProxyProxyBaseModel(ProxyBaseModel): + class Meta: + proxy = True + class LengthModel(models.Model): data = models.IntegerField() diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py index d8c5faba145..704e34b8ba2 100644 --- a/tests/regressiontests/serializers_regress/tests.py +++ b/tests/regressiontests/serializers_regress/tests.py @@ -41,8 +41,8 @@ from .models import (BooleanData, CharData, DateData, DateTimeData, EmailData, GenericIPAddressPKData, PhonePKData, PositiveIntegerPKData, PositiveSmallIntegerPKData, SlugPKData, SmallPKData, USStatePKData, AutoNowDateTimeData, ModifyingSaveData, InheritAbstractModel, BaseModel, - ExplicitInheritBaseModel, InheritBaseModel, ProxyBaseModel, BigIntegerData, - LengthModel, Tag, ComplexModel) + ExplicitInheritBaseModel, InheritBaseModel, ProxyBaseModel, + ProxyProxyBaseModel, BigIntegerData, LengthModel, Tag, ComplexModel) # A set of functions that can be used to recreate # test data objects of various kinds. @@ -410,11 +410,14 @@ class SerializerTests(TestCase): def test_serialize_proxy_model(self): BaseModel.objects.create(parent_data=1) - base_objects = BaseModel.objects.all() + base_objects = BaseModel.objects.all() proxy_objects = ProxyBaseModel.objects.all() - base_data = serializers.serialize("json", base_objects) + proxy_proxy_objects = ProxyProxyBaseModel.objects.all() + base_data = serializers.serialize("json", base_objects) proxy_data = serializers.serialize("json", proxy_objects) + proxy_proxy_data = serializers.serialize("json", proxy_proxy_objects) self.assertEqual(base_data, proxy_data.replace('proxy', '')) + self.assertEqual(base_data, proxy_proxy_data.replace('proxy', '')) def serializerTest(format, self):