Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17717 (again) -- Used the new API for concrete models added in…

… r17573. Many thanks to Simon Charette and Anssi Kääriäinen.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dd441701ced9621f184f8e601339cfb9c16a844b 1 parent 7ce1ad7
Jannis Leidel authored March 03, 2012
6  django/core/serializers/base.py
@@ -43,8 +43,8 @@ def serialize(self, queryset, **options):
43 43
             self.start_object(obj)
44 44
             # Use the concrete parent class' _meta instead of the object's _meta
45 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:
  46
+            concrete_model = obj._meta.concrete_model
  47
+            for field in concrete_model._meta.local_fields:
48 48
                 if field.serialize:
49 49
                     if field.rel is None:
50 50
                         if self.selected_fields is None or field.attname in self.selected_fields:
@@ -52,7 +52,7 @@ def serialize(self, queryset, **options):
52 52
                     else:
53 53
                         if self.selected_fields is None or field.attname[:-3] in self.selected_fields:
54 54
                             self.handle_fk_field(obj, field)
55  
-            for field in concrete_class._meta.many_to_many:
  55
+            for field in concrete_model._meta.many_to_many:
56 56
                 if field.serialize:
57 57
                     if self.selected_fields is None or field.attname in self.selected_fields:
58 58
                         self.handle_m2m_field(obj, field)
4  tests/regressiontests/serializers_regress/models.py
@@ -263,6 +263,10 @@ class ProxyBaseModel(BaseModel):
263 263
     class Meta:
264 264
         proxy = True
265 265
 
  266
+class ProxyProxyBaseModel(ProxyBaseModel):
  267
+    class Meta:
  268
+        proxy = True
  269
+
266 270
 class LengthModel(models.Model):
267 271
     data = models.IntegerField()
268 272
 
11  tests/regressiontests/serializers_regress/tests.py
@@ -41,8 +41,8 @@
41 41
     GenericIPAddressPKData, PhonePKData, PositiveIntegerPKData,
42 42
     PositiveSmallIntegerPKData, SlugPKData, SmallPKData, USStatePKData,
43 43
     AutoNowDateTimeData, ModifyingSaveData, InheritAbstractModel, BaseModel,
44  
-    ExplicitInheritBaseModel, InheritBaseModel, ProxyBaseModel, BigIntegerData,
45  
-    LengthModel, Tag, ComplexModel)
  44
+    ExplicitInheritBaseModel, InheritBaseModel, ProxyBaseModel,
  45
+    ProxyProxyBaseModel, BigIntegerData, 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.
@@ -410,11 +410,14 @@ def test_yaml_deserializer_exception(self):
410 410
 
411 411
     def test_serialize_proxy_model(self):
412 412
         BaseModel.objects.create(parent_data=1)
413  
-        base_objects  = BaseModel.objects.all()
  413
+        base_objects = BaseModel.objects.all()
414 414
         proxy_objects = ProxyBaseModel.objects.all()
415  
-        base_data  = serializers.serialize("json", base_objects)
  415
+        proxy_proxy_objects = ProxyProxyBaseModel.objects.all()
  416
+        base_data = serializers.serialize("json", base_objects)
416 417
         proxy_data = serializers.serialize("json", proxy_objects)
  418
+        proxy_proxy_data = serializers.serialize("json", proxy_proxy_objects)
417 419
         self.assertEqual(base_data, proxy_data.replace('proxy', ''))
  420
+        self.assertEqual(base_data, proxy_proxy_data.replace('proxy', ''))
418 421
 
419 422
 
420 423
 def serializerTest(format, self):

0 notes on commit dd44170

Please sign in to comment.
Something went wrong with that request. Please try again.