summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Cahoon <chris.cahoon@gmail.com>2009-06-13 03:30:36 +0000
committerChris Cahoon <chris.cahoon@gmail.com>2009-06-13 03:30:36 +0000
commitc81aa42bc70e55fd3f4d9164834b390e7b6c1747 (patch)
treeff6c5d85e3f0f0b14745d6ff25df6b17ac66c4c6
parent1015dad87d7f015f574ff0af70c3b6b1c0427651 (diff)
downloaddjango-c81aa42bc70e55fd3f4d9164834b390e7b6c1747.tar.gz
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/branches/soc2009/http-wsgi-improvements@11002 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/base.py4
-rw-r--r--tests/modeltests/proxy_models/fixtures/mypeople.json9
-rw-r--r--tests/modeltests/proxy_models/models.py14
3 files changed, 26 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 325e8764f1..a5c99865a6 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -435,7 +435,9 @@ class Model(object):
# 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:
+ # We also go through this process to defer the save of proxy objects
+ # to their actual underlying model.
+ if not raw or meta.proxy:
if meta.proxy:
org = cls
else:
diff --git a/tests/modeltests/proxy_models/fixtures/mypeople.json b/tests/modeltests/proxy_models/fixtures/mypeople.json
new file mode 100644
index 0000000000..d20c8f2a6e
--- /dev/null
+++ b/tests/modeltests/proxy_models/fixtures/mypeople.json
@@ -0,0 +1,9 @@
+[
+ {
+ "pk": 100,
+ "model": "proxy_models.myperson",
+ "fields": {
+ "name": "Elvis Presley"
+ }
+ }
+] \ No newline at end of file
diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py
index 4074a323ae..e38266fb70 100644
--- a/tests/modeltests/proxy_models/models.py
+++ b/tests/modeltests/proxy_models/models.py
@@ -286,6 +286,13 @@ MyPerson post save
MyPersonProxy pre save
MyPersonProxy post save
+>>> signals.pre_save.disconnect(h1, sender=MyPerson)
+>>> signals.post_save.disconnect(h2, sender=MyPerson)
+>>> signals.pre_save.disconnect(h3, sender=Person)
+>>> signals.post_save.disconnect(h4, sender=Person)
+>>> signals.pre_save.disconnect(h5, sender=MyPersonProxy)
+>>> signals.post_save.disconnect(h6, sender=MyPersonProxy)
+
# A proxy has the same content type as the model it is proxying for (at the
# storage level, it is meant to be essentially indistinguishable).
>>> ctype = ContentType.objects.get_for_model
@@ -354,4 +361,11 @@ True
# Select related + filter on a related proxy of proxy field
>>> ProxyImprovement.objects.select_related().get(associated_bug__summary__icontains='fix')
<ProxyImprovement: ProxyImprovement:improve that>
+
+Proxy models can be loaded from fixtures (Regression for #11194)
+>>> from django.core import management
+>>> management.call_command('loaddata', 'mypeople.json', verbosity=0)
+>>> MyPerson.objects.get(pk=100)
+<MyPerson: Elvis Presley>
+
"""}