Skip to content

Commit 6f44967

Browse files
Vayelvdboor
authored andcommitted
Make it possible to use custom keyword args in model class definition
For instance to easily customize subclasses through __init_subclass__().
1 parent 81c2d81 commit 6f44967

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

polymorphic/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class PolymorphicModelBase(ModelBase):
5757
PolymorphicQuerySet.
5858
"""
5959

60-
def __new__(self, model_name, bases, attrs):
60+
def __new__(self, model_name, bases, attrs, **kwargs):
6161
# print; print '###', model_name, '- bases:', bases
6262

6363
# Workaround compatibility issue with six.with_metaclass() and custom Django model metaclasses:
6464
if not attrs and model_name == "NewBase":
6565
return super(PolymorphicModelBase, self).__new__(
66-
self, model_name, bases, attrs
66+
self, model_name, bases, attrs, **kwargs
6767
)
6868

6969
# Make sure that manager_inheritance_from_future is set, since django-polymorphic 1.x already
@@ -78,7 +78,7 @@ def __new__(self, model_name, bases, attrs):
7878
)
7979

8080
# create new model
81-
new_class = self.call_superclass_new_method(model_name, bases, attrs)
81+
new_class = self.call_superclass_new_method(model_name, bases, attrs, **kwargs)
8282

8383
# check if the model fields are all allowed
8484
self.validate_model_fields(new_class)
@@ -100,7 +100,7 @@ def __new__(self, model_name, bases, attrs):
100100
return new_class
101101

102102
@classmethod
103-
def call_superclass_new_method(self, model_name, bases, attrs):
103+
def call_superclass_new_method(self, model_name, bases, attrs, **kwargs):
104104
"""call __new__ method of super class and return the newly created class.
105105
Also work around a limitation in Django's ModelBase."""
106106
# There seems to be a general limitation in Django's app_label handling
@@ -119,7 +119,7 @@ def call_superclass_new_method(self, model_name, bases, attrs):
119119
if do_app_label_workaround:
120120
meta.app_label = "poly_dummy_app_label"
121121
new_class = super(PolymorphicModelBase, self).__new__(
122-
self, model_name, bases, attrs
122+
self, model_name, bases, attrs, **kwargs
123123
)
124124
if do_app_label_workaround:
125125
del meta.app_label

0 commit comments

Comments
 (0)