Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@freakboy3742 freakboy3742 authored
View
4 django/db/models/base.py
@@ -435,7 +435,9 @@ def save_base(self, raw=False, cls=None, origin=None,
# 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:
View
9 tests/modeltests/proxy_models/fixtures/mypeople.json
@@ -0,0 +1,9 @@
+[
+ {
+ "pk": 100,
+ "model": "proxy_models.myperson",
+ "fields": {
+ "name": "Elvis Presley"
+ }
+ }
+]
View
14 tests/modeltests/proxy_models/models.py
@@ -286,6 +286,13 @@ class Meta:
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 @@ class Meta:
# 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>
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.