Ticket #10953: proxy-proxy.2.diff

File proxy-proxy.2.diff, 3.2 KB (added by Alex, 6 years ago)
  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 05cd0d9..3a3fbf1 100644
    a b class ModelBase(type): 
    116116                    new_class._meta.local_many_to_many):
    117117                raise FieldError("Proxy model '%s' contains model fields."
    118118                        % name)
     119            while base._meta.proxy:
     120                base = base._meta.proxy_for_model
    119121            new_class._meta.setup_proxy(base)
    120122
    121123        # Do the appropriate setup for any model parents.
    class ModelBase(type): 
    123125                if isinstance(f, OneToOneField)])
    124126
    125127        for base in parents:
     128            original_base = base
    126129            if not hasattr(base, '_meta'):
    127130                # Things without _meta aren't functional models, so they're
    128131                # uninteresting parents.
    class ModelBase(type): 
    167170            # Proxy models inherit the non-abstract managers from their base,
    168171            # unless they have redefined any of them.
    169172            if is_proxy:
    170                 new_class.copy_managers(base._meta.concrete_managers)
     173                new_class.copy_managers(original_base._meta.concrete_managers)
    171174
    172175            # Inherit virtual fields (like GenericForeignKey) from the parent
    173176            # class
  • django/db/models/manager.py

    diff --git a/django/db/models/manager.py b/django/db/models/manager.py
    index 57844f2..52612d8 100644
    a b class Manager(object): 
    5757        setattr(model, name, ManagerDescriptor(self))
    5858        if not getattr(model, '_default_manager', None) or self.creation_counter < model._default_manager.creation_counter:
    5959            model._default_manager = self
    60         if model._meta.abstract or self._inherited:
     60        if model._meta.abstract or (self._inherited and not self.model._meta.proxy):
    6161            model._meta.abstract_managers.append((self.creation_counter, name,
    6262                    self))
    6363        else:
  • tests/modeltests/proxy_models/models.py

    diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py
    index ab38112..f0ee626 100644
    a b class MyPersonProxy(MyPerson): 
    8282class LowerStatusPerson(MyPersonProxy):
    8383    status = models.CharField(max_length=80)
    8484
     85class User(models.Model):
     86    name = models.CharField(max_length=100)
     87
     88    def __unicode__(self):
     89        return self.name
     90
     91class UserProxy(User):
     92    class Meta:
     93        proxy = True
     94
     95class UserProxyProxy(UserProxy):
     96    class Meta:
     97        proxy = True
     98
    8599__test__ = {'API_TESTS' : """
    86100# The MyPerson model should be generating the same database queries as the
    87101# Person model (when the same manager is used in each case).
    FieldError: Proxy model 'NoNewFields' contains model fields. 
    178192>>> ctype = ContentType.objects.get_for_model
    179193>>> ctype(Person) is ctype(OtherPerson)
    180194True
    181 """}
    182195
     196>>> MyPersonProxy.objects.all()
     197[<MyPersonProxy: barney>, <MyPersonProxy: fred>]
    183198
     199>>> u = User.objects.create(name='Bruce')
     200>>> User.objects.all()
     201[<User: Bruce>]
     202>>> UserProxy.objects.all()
     203[<UserProxy: Bruce>]
     204>>> UserProxyProxy.objects.all()
     205[<UserProxyProxy: Bruce>]
     206"""}
Back to Top