@@ -52,9 +52,9 @@ class PolymorphicModelBase(ModelBase):
5252 PolymorphicQuerySet.
5353 """
5454
55- def __new__ (self , model_name , bases , attrs , ** kwargs ):
55+ def __new__ (cls , model_name , bases , attrs , ** kwargs ):
5656 # create new model
57- new_class = self . call_superclass_new_method ( model_name , bases , attrs , ** kwargs )
57+ new_class = super (). __new__ ( cls , model_name , bases , attrs , ** kwargs )
5858
5959 if new_class ._meta .base_manager_name is None :
6060 # by default, use polymorphic manager as the base manager - i.e. for
@@ -64,11 +64,11 @@ def __new__(self, model_name, bases, attrs, **kwargs):
6464 new_class ._meta .base_manager_name = "objects"
6565
6666 # check if the model fields are all allowed
67- self .validate_model_fields (new_class )
67+ cls .validate_model_fields (new_class )
6868
6969 # validate resulting default manager
7070 if not new_class ._meta .abstract and not new_class ._meta .swapped :
71- self .validate_model_manager (new_class .objects , model_name , "objects" )
71+ cls .validate_model_manager (new_class .objects , model_name , "objects" )
7272
7373 # for __init__ function of this class (monkeypatching inheritance accessors)
7474 new_class .polymorphic_super_sub_accessors_replaced = False
@@ -89,20 +89,7 @@ def call_superclass_new_method(self, model_name, bases, attrs, **kwargs):
8989 # We run into this problem if polymorphic.py is located in a top-level directory
9090 # which is directly in the python path. To work around this we temporarily set
9191 # app_label here for PolymorphicModel.
92- meta = attrs .get ("Meta" , None )
93- do_app_label_workaround = (
94- meta
95- and attrs ["__module__" ] == "polymorphic"
96- and model_name == "PolymorphicModel"
97- and getattr (meta , "app_label" , None ) is None
98- )
99-
100- if do_app_label_workaround :
101- meta .app_label = "poly_dummy_app_label"
102- new_class = super ().__new__ (self , model_name , bases , attrs , ** kwargs )
103- if do_app_label_workaround :
104- del meta .app_label
105- return new_class
92+ return super ().__new__ (self , model_name , bases , attrs , ** kwargs )
10693
10794 @classmethod
10895 def validate_model_fields (self , new_class ):
@@ -115,7 +102,7 @@ def validate_model_fields(self, new_class):
115102 )
116103
117104 @classmethod
118- def validate_model_manager (self , manager , model_name , manager_name ):
105+ def validate_model_manager (cls , manager , model_name , manager_name ):
119106 """check if the manager is derived from PolymorphicManager
120107 and its querysets from PolymorphicQuerySet - throw AssertionError if not"""
121108
0 commit comments