def get_duplicated_model(self, class_inst, new_class_name):
        """
        Duplicate the model fields from class_inst to new_class_name, example:
        NewClass = get_duplicated_model(OldClass, "NewClass")
        :param class_inst:
        :param new_class_name:
        :return:
        """
        # Ref: http://www.cnblogs.com/Jerryshome/archive/2012/12/21/2827492.html
        attr_dict = {'__module__': self.module_name}
        for field in class_inst.__dict__['_meta'].fields:
            if self.is_relation_field_needed:
                attr_dict[field.name] = copy_field(field)
            elif not is_relation_field(field):
                attr_dict[field.name] = copy_field(field)
        # duplicated_model_class = type("Meta", (), {"abstract": True})
        duplicated_model_class = type(new_class_name, (models.Model,), attr_dict)
        # The following codes are not working
        # if hasattr(class_inst, "__str__"):
        #     setattr(duplicated_model_class, "__str__", getattr(class_inst, "__str__"))
        # if hasattr(class_inst, "__str__"):
        #     str_func = getattr(class_inst, "__str__")
        #     duplicated_model_class.__str__ = str_func
        return duplicated_model_class
def get_duplicated_model ( self , class_inst , new_class_name ) : attr_dict = { '__module__' : self . module_name } for field in class_inst . __dict__ [ '_meta' ] . fields : if self . is_relation_field_needed : attr_dict [ field . name ] = copy_field ( field ) elif not is_relation_field ( field ) : attr_dict [ field . name ] = copy_field ( field ) duplicated_model_class = type ( new_class_name , ( models . Model , ) , attr_dict ) return duplicated_model_class
Duplicate the model fields from class_inst to new_class_name, example:
        NewClass = get_duplicated_model(OldClass, "NewClass")
        :param class_inst:
        :param new_class_name:
        :return: