Ticket #11560: multiple_proxy_models.diff

File multiple_proxy_models.diff, 3.4 KB (added by Ryan Kelly, 14 years ago)
  • docs/topics/db/models.txt

     
    11041104proxy model can inherit from any number of abstract model classes, providing
    11051105they do *not* define any model fields.
    11061106
     1107A proxy model can also inherit from any number of proxy model classes, as
     1108long as they all share a common non-abstract parent class.
     1109
    11071110Proxy models inherit any ``Meta`` options that they don't define from their
    11081111non-abstract model parent (the model they are proxying for).
    11091112
  • django/db/models/base.py

     
    111111                        raise TypeError("Abstract base class containing model fields not permitted for proxy model '%s'." % name)
    112112                    else:
    113113                        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:
    115117                    raise TypeError("Proxy model '%s' has more than one non-abstract model base class." % name)
    116118                else:
    117119                    base = parent
  • tests/modeltests/proxy_models/tests.py

     
    1010from models import MyPersonProxy, Abstract, OtherPerson, User, UserProxy
    1111from models import UserProxyProxy, Country, State, StateProxy, TrackerUser
    1212from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug
    13 from models import ProxyBug, ProxyImprovement
     13from models import ProxyBug, ProxyImprovement, RepeatedUserProxy
    1414
    1515class ProxyModelTests(TestCase):
    1616    def test_same_manager_queries(self):
     
    231231        resp = [u.name for u in UserProxyProxy.objects.all()]
    232232        self.assertEqual(resp, ['Bruce'])
    233233
     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
    234246    def test_proxy_delete(self):
    235247        """
    236248        Proxy objects can be deleted
  • tests/modeltests/proxy_models/models.py

     
    9696    class Meta:
    9797        proxy = True
    9898
     99class AnotherUserProxy(User):
     100    class Meta:
     101        proxy = True
     102
     103class RepeatedUserProxy(UserProxy,AnotherUserProxy):
     104    class Meta:
     105        proxy = True
     106
    99107# We can still use `select_related()` to include related models in our querysets.
    100108class Country(models.Model):
    101109    name = models.CharField(max_length=50)
     
    161169
    162170class ProxyImprovement(Improvement):
    163171    class Meta:
    164         proxy = True
    165  No newline at end of file
     172        proxy = True
Back to Top