Code

Ticket #10953: proxy-proxy.diff

File proxy-proxy.diff, 1.8 KB (added by Alex, 5 years ago)
Line 
1diff --git a/django/db/models/base.py b/django/db/models/base.py
2index 05cd0d9..3a3fbf1 100644
3--- a/django/db/models/base.py
4+++ b/django/db/models/base.py
5@@ -116,6 +116,8 @@ class ModelBase(type):
6                     new_class._meta.local_many_to_many):
7                 raise FieldError("Proxy model '%s' contains model fields."
8                         % name)
9+            while base._meta.proxy:
10+                base = base._meta.proxy_for_model
11             new_class._meta.setup_proxy(base)
12 
13         # Do the appropriate setup for any model parents.
14@@ -123,6 +125,7 @@ class ModelBase(type):
15                 if isinstance(f, OneToOneField)])
16 
17         for base in parents:
18+            original_base = base
19             if not hasattr(base, '_meta'):
20                 # Things without _meta aren't functional models, so they're
21                 # uninteresting parents.
22@@ -167,7 +170,7 @@ class ModelBase(type):
23             # Proxy models inherit the non-abstract managers from their base,
24             # unless they have redefined any of them.
25             if is_proxy:
26-                new_class.copy_managers(base._meta.concrete_managers)
27+                new_class.copy_managers(original_base._meta.concrete_managers)
28 
29             # Inherit virtual fields (like GenericForeignKey) from the parent
30             # class
31diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py
32index ab38112..1c380e8 100644
33--- a/tests/modeltests/proxy_models/models.py
34+++ b/tests/modeltests/proxy_models/models.py
35@@ -178,6 +178,7 @@ FieldError: Proxy model 'NoNewFields' contains model fields.
36 >>> ctype = ContentType.objects.get_for_model
37 >>> ctype(Person) is ctype(OtherPerson)
38 True
39-"""}
40-
41 
42+>>> MyPersonProxy.objects.all()
43+[<MyPersonProxy: barney>, <MyPersonProxy: fred>]
44+"""}