Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11194 -- Corrected loading of Proxy models from fixtures (and,…

… by extension, save_base(raw=True) for Proxy models).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10955 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 031385e4cc3be747319458eab5ba80270a5285f9 1 parent 81aedbd
Russell Keith-Magee authored June 08, 2009
4  django/db/models/base.py
@@ -435,7 +435,9 @@ def save_base(self, raw=False, cls=None, origin=None,
435 435
         # That means that we don't try to be smart about saving attributes
436 436
         # that might have come from the parent class - we just save the
437 437
         # attributes we have been given to the class we have been given.
438  
-        if not raw:
  438
+        # We also go through this process to defer the save of proxy objects
  439
+        # to their actual underlying model.
  440
+        if not raw or meta.proxy:
439 441
             if meta.proxy:
440 442
                 org = cls
441 443
             else:
9  tests/modeltests/proxy_models/fixtures/mypeople.json
... ...
@@ -0,0 +1,9 @@
  1
+[
  2
+    {
  3
+        "pk": 100,
  4
+        "model": "proxy_models.myperson",
  5
+        "fields": {
  6
+            "name": "Elvis Presley"
  7
+        }
  8
+    }
  9
+]
14  tests/modeltests/proxy_models/models.py
@@ -286,6 +286,13 @@ class Meta:
286 286
 MyPersonProxy pre save
287 287
 MyPersonProxy post save
288 288
 
  289
+>>> signals.pre_save.disconnect(h1, sender=MyPerson)
  290
+>>> signals.post_save.disconnect(h2, sender=MyPerson)
  291
+>>> signals.pre_save.disconnect(h3, sender=Person)
  292
+>>> signals.post_save.disconnect(h4, sender=Person)
  293
+>>> signals.pre_save.disconnect(h5, sender=MyPersonProxy)
  294
+>>> signals.post_save.disconnect(h6, sender=MyPersonProxy)
  295
+
289 296
 # A proxy has the same content type as the model it is proxying for (at the
290 297
 # storage level, it is meant to be essentially indistinguishable).
291 298
 >>> ctype = ContentType.objects.get_for_model
@@ -354,4 +361,11 @@ class Meta:
354 361
 # Select related + filter on a related proxy of proxy field
355 362
 >>> ProxyImprovement.objects.select_related().get(associated_bug__summary__icontains='fix')
356 363
 <ProxyImprovement: ProxyImprovement:improve that>
  364
+
  365
+Proxy models can be loaded from fixtures (Regression for #11194)
  366
+>>> from django.core import management
  367
+>>> management.call_command('loaddata', 'mypeople.json', verbosity=0)
  368
+>>> MyPerson.objects.get(pk=100)
  369
+<MyPerson: Elvis Presley>
  370
+
357 371
 """}

0 notes on commit 031385e

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