@classmethod
def get_subclass(cls, obj):
    """ Get the subclass to use when instantiating a polymorphic object.
            The default implementation looks at ``cls.config_polymorphic``
            to get the name of an attribute.  Subclasses automatically
            register their value for that attribute on creation via their
            ``config_polymorphic_identity`` field.  This process is then
            repeated recursively until None is returned (indicating that the
            current class is the correct one)

            This method can be overridden to allow any method you would like
            to use to select subclasses. It should return either the subclass
            to use or None, if the original class should be used.
        """
    if cls.config_polymorphic is None:
        return
    value = obj.get(cls.config_polymorphic)
    value = cls._subclasses.get(value)
    if value == cls or value is None:
        return None
    sub_value = value.get_subclass(obj)
    if sub_value is None:
        return value
    return sub_value
