diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index c7e6226..e4bba1d 100644
a
|
b
|
class Serializer(object):
|
41 | 41 | self.start_serialization() |
42 | 42 | for obj in queryset: |
43 | 43 | self.start_object(obj) |
44 | | for field in obj._meta.local_fields: |
| 44 | # Use the concrete parent class' _meta instead of the object's _meta |
| 45 | # This is to avoid local_fields problems for proxy models. Refs #17717. |
| 46 | concrete_class = obj._meta.proxy_for_model or obj.__class__ |
| 47 | for field in concrete_class._meta.local_fields: |
45 | 48 | if field.serialize: |
46 | 49 | if field.rel is None: |
47 | 50 | if self.selected_fields is None or field.attname in self.selected_fields: |
… |
… |
class Serializer(object):
|
49 | 52 | else: |
50 | 53 | if self.selected_fields is None or field.attname[:-3] in self.selected_fields: |
51 | 54 | self.handle_fk_field(obj, field) |
52 | | for field in obj._meta.many_to_many: |
| 55 | for field in concrete_class._meta.many_to_many: |
53 | 56 | if field.serialize: |
54 | 57 | if self.selected_fields is None or field.attname in self.selected_fields: |
55 | 58 | self.handle_m2m_field(obj, field) |
diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py
index b3ae1fe..9381349 100644
a
|
b
|
class ExplicitInheritBaseModel(BaseModel):
|
259 | 259 | parent = models.OneToOneField(BaseModel) |
260 | 260 | child_data = models.IntegerField() |
261 | 261 | |
| 262 | class ProxyBaseModel(BaseModel): |
| 263 | class Meta: |
| 264 | proxy = True |
| 265 | |
262 | 266 | class LengthModel(models.Model): |
263 | 267 | data = models.IntegerField() |
264 | 268 | |
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index 5abff63..d8c5fab 100644
a
|
b
|
from .models import (BooleanData, CharData, DateData, DateTimeData, EmailData,
|
40 | 40 | DecimalPKData, FloatPKData, IntegerPKData, IPAddressPKData, |
41 | 41 | GenericIPAddressPKData, PhonePKData, PositiveIntegerPKData, |
42 | 42 | PositiveSmallIntegerPKData, SlugPKData, SmallPKData, USStatePKData, |
43 | | AutoNowDateTimeData, ModifyingSaveData, InheritAbstractModel, |
44 | | ExplicitInheritBaseModel, InheritBaseModel, BigIntegerData, LengthModel, |
45 | | Tag, ComplexModel) |
| 43 | AutoNowDateTimeData, ModifyingSaveData, InheritAbstractModel, BaseModel, |
| 44 | ExplicitInheritBaseModel, InheritBaseModel, ProxyBaseModel, BigIntegerData, |
| 45 | LengthModel, Tag, ComplexModel) |
46 | 46 | |
47 | 47 | # A set of functions that can be used to recreate |
48 | 48 | # test data objects of various kinds. |
… |
… |
class SerializerTests(TestCase):
|
408 | 408 | for obj in serializers.deserialize("yaml", "{"): |
409 | 409 | pass |
410 | 410 | |
| 411 | def test_serialize_proxy_model(self): |
| 412 | BaseModel.objects.create(parent_data=1) |
| 413 | base_objects = BaseModel.objects.all() |
| 414 | proxy_objects = ProxyBaseModel.objects.all() |
| 415 | base_data = serializers.serialize("json", base_objects) |
| 416 | proxy_data = serializers.serialize("json", proxy_objects) |
| 417 | self.assertEqual(base_data, proxy_data.replace('proxy', '')) |
| 418 | |
411 | 419 | |
412 | 420 | def serializerTest(format, self): |
413 | 421 | |