Ticket #11560: multiple_proxy_models.diff
File multiple_proxy_models.diff, 3.4 KB (added by , 14 years ago) |
---|
-
docs/topics/db/models.txt
1104 1104 proxy model can inherit from any number of abstract model classes, providing 1105 1105 they do *not* define any model fields. 1106 1106 1107 A proxy model can also inherit from any number of proxy model classes, as 1108 long as they all share a common non-abstract parent class. 1109 1107 1110 Proxy models inherit any ``Meta`` options that they don't define from their 1108 1111 non-abstract model parent (the model they are proxying for). 1109 1112 -
django/db/models/base.py
111 111 raise TypeError("Abstract base class containing model fields not permitted for proxy model '%s'." % name) 112 112 else: 113 113 continue 114 if base is not None: 114 while parent._meta.proxy: 115 parent = parent._meta.proxy_for_model 116 if base is not None and base is not parent: 115 117 raise TypeError("Proxy model '%s' has more than one non-abstract model base class." % name) 116 118 else: 117 119 base = parent -
tests/modeltests/proxy_models/tests.py
10 10 from models import MyPersonProxy, Abstract, OtherPerson, User, UserProxy 11 11 from models import UserProxyProxy, Country, State, StateProxy, TrackerUser 12 12 from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug 13 from models import ProxyBug, ProxyImprovement 13 from models import ProxyBug, ProxyImprovement, RepeatedUserProxy 14 14 15 15 class ProxyModelTests(TestCase): 16 16 def test_same_manager_queries(self): … … 231 231 resp = [u.name for u in UserProxyProxy.objects.all()] 232 232 self.assertEqual(resp, ['Bruce']) 233 233 234 def test_user_repeateduserproxy(self): 235 User.objects.create(name='Bruce') 236 237 resp = [u.name for u in User.objects.all()] 238 self.assertEqual(resp, ['Bruce']) 239 240 resp = [u.name for u in UserProxy.objects.all()] 241 self.assertEqual(resp, ['Bruce']) 242 243 resp = [u.name for u in RepeatedUserProxy.objects.all()] 244 self.assertEqual(resp, ['Bruce']) 245 234 246 def test_proxy_delete(self): 235 247 """ 236 248 Proxy objects can be deleted -
tests/modeltests/proxy_models/models.py
96 96 class Meta: 97 97 proxy = True 98 98 99 class AnotherUserProxy(User): 100 class Meta: 101 proxy = True 102 103 class RepeatedUserProxy(UserProxy,AnotherUserProxy): 104 class Meta: 105 proxy = True 106 99 107 # We can still use `select_related()` to include related models in our querysets. 100 108 class Country(models.Model): 101 109 name = models.CharField(max_length=50) … … 161 169 162 170 class ProxyImprovement(Improvement): 163 171 class Meta: 164 proxy = True 165 No newline at end of file 172 proxy = True