Merge pull request #307 from skirsdeda/master
Swapped polymorphic models don't work on Django>=1.10fix_request_path_info
commit
b9ee2c7ab6
|
|
@ -94,11 +94,12 @@ class PolymorphicModelBase(ModelBase):
|
||||||
new_class._default_manager = user_manager._copy_to_model(new_class)
|
new_class._default_manager = user_manager._copy_to_model(new_class)
|
||||||
new_class._default_manager._inherited = False # the default mgr was defined by the user, not inherited
|
new_class._default_manager._inherited = False # the default mgr was defined by the user, not inherited
|
||||||
|
|
||||||
# validate resulting default manager
|
# validate resulting default manager (only on non-abstract and non-swapped models)
|
||||||
if django.VERSION >= (1, 10) and not new_class._meta.abstract:
|
if not new_class._meta.abstract and not new_class._meta.swapped:
|
||||||
self.validate_model_manager(new_class.objects, model_name, 'objects')
|
if django.VERSION >= (1, 10):
|
||||||
else:
|
self.validate_model_manager(new_class.objects, model_name, 'objects')
|
||||||
self.validate_model_manager(new_class._default_manager, model_name, '_default_manager')
|
else:
|
||||||
|
self.validate_model_manager(new_class._default_manager, model_name, '_default_manager')
|
||||||
|
|
||||||
# for __init__ function of this class (monkeypatching inheritance accessors)
|
# for __init__ function of this class (monkeypatching inheritance accessors)
|
||||||
new_class.polymorphic_super_sub_accessors_replaced = False
|
new_class.polymorphic_super_sub_accessors_replaced = False
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,23 @@ class DateModel(PolymorphicModel):
|
||||||
date = models.DateTimeField()
|
date = models.DateTimeField()
|
||||||
|
|
||||||
|
|
||||||
|
# Define abstract and swappable (being swapped for SwappedModel) models
|
||||||
|
# To test manager validation (should be skipped for such models)
|
||||||
|
class AbstractModel(PolymorphicModel):
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class SwappableModel(AbstractModel):
|
||||||
|
class Meta:
|
||||||
|
swappable = 'POLYMORPHIC_TEST_SWAPPABLE'
|
||||||
|
|
||||||
|
|
||||||
|
class SwappedModel(AbstractModel):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Import tests
|
# Import tests
|
||||||
from .test_admin import *
|
from .test_admin import *
|
||||||
from .test_orm import *
|
from .test_orm import *
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ if not settings.configured:
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
POLYMORPHIC_TEST_SWAPPABLE='polymorphic.swappedmodel',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue