File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -13,28 +13,24 @@ class ModelMixin(object):
1313 """
1414
1515 @classmethod
16- def model_mixin (cls ):
16+ def model_mixin (cls , target ):
1717 """
18- Adds the fields of the class to the all classes that mix it in
18+ Adds the fields of the class to the target passed in.
1919 """
20+ assert issubclass (target , models .Model )
21+
2022 fields = {}
2123
2224 for (name , attr ) in cls .__dict__ .items ():
2325 if isinstance (attr , models .Field ):
2426 fields [name ] = attr
2527
26- for fieldname in fields .keys ():
27- delattr (cls , fieldname )
28-
29- for subclass in cls .__subclasses__ ():
30- assert issubclass (subclass , models .Model )
31- for (fieldname , field ) in fields .items ():
32- field .contribute_to_class (subclass , fieldname )
33-
28+ for (key , field ) in fields .items ():
29+ field .contribute_to_class (target , key )
3430
3531
3632@receiver (class_prepared )
3733def mixin (sender , ** kwargs ):
3834 for base in sender .__bases__ :
3935 if issubclass (base , ModelMixin ):
40- base .model_mixin ()
36+ base .model_mixin (sender )
You can’t perform that action at this time.
0 commit comments