Fixed unwanted manager replacement in Django 1.11 projects.
Django 1.11 uses the old manager inheritance system, unless it's
overwritten with manager_inheritance_from_future. With a class layout
like:
PolymorphicModel (abstract)
PolymorphicMPTTModel (abstract)
GenericCustomer (concrete, has objects = ...)
CustomerGroupBase (abstract, has objects = ...)
Partner (concrete, no manager)
BranchPartner (concrete, no manager)
The last level gets a normal Django Manager instead of the polymorphic
manager. Because the PolymorphicModel had a base_objects manager, this
was typically used as _default_manager. Now that the default manager is
no longer affected, it's also easier to detect why the "objects" doesn't
get the proper manager type. Using "manager_inheritance_from_future" is
recommended instead to have both the right behavior and forward
Django 2.x compatibility.
This commit is contained in:
@@ -191,7 +191,9 @@ class MROBase1(ShowFieldType, PolymorphicModel):
|
||||
|
||||
|
||||
class MROBase2(MROBase1):
|
||||
pass # Django vanilla inheritance does not inherit MyManager as _default_manager here
|
||||
class Meta:
|
||||
# Django 1.x inheritance does not inherit MyManager as _default_manager here
|
||||
manager_inheritance_from_future = True
|
||||
|
||||
|
||||
class MROBase3(models.Model):
|
||||
@@ -200,7 +202,8 @@ class MROBase3(models.Model):
|
||||
|
||||
|
||||
class MRODerived(MROBase2, MROBase3):
|
||||
pass
|
||||
class Meta:
|
||||
manager_inheritance_from_future = True
|
||||
|
||||
|
||||
class ParentModelWithManager(PolymorphicModel):
|
||||
|
||||
Reference in New Issue
Block a user