diff --git a/sqlalchemy_utils/types/choice.py b/sqlalchemy_utils/types/choice.py index 124973b..7527f34 100644 --- a/sqlalchemy_utils/types/choice.py +++ b/sqlalchemy_utils/types/choice.py @@ -40,6 +40,10 @@ class ChoiceType(types.TypeDecorator, ScalarCoercible): if impl: self.impl = impl + @property + def python_type(self): + return self.impl.python_type + def _coerce(self, value): if value is None: return value diff --git a/sqlalchemy_utils/types/color.py b/sqlalchemy_utils/types/color.py index 5fb4791..e8f35e8 100644 --- a/sqlalchemy_utils/types/color.py +++ b/sqlalchemy_utils/types/color.py @@ -17,6 +17,7 @@ class ColorType(types.TypeDecorator, ScalarCoercible): """ STORE_FORMAT = u'hex' impl = types.Unicode(20) + python_type = colour.Color def __init__(self, max_length=20, *args, **kwargs): # Fail if colour is not found. diff --git a/sqlalchemy_utils/types/country.py b/sqlalchemy_utils/types/country.py index 8618825..b05fe0c 100644 --- a/sqlalchemy_utils/types/country.py +++ b/sqlalchemy_utils/types/country.py @@ -40,6 +40,7 @@ class CountryType(types.TypeDecorator, ScalarCoercible): """ impl = types.String(2) + python_type = Country def process_bind_param(self, value, dialect): if isinstance(value, Country): diff --git a/tests/types/test_choice.py b/tests/types/test_choice.py index 6f727b4..6e495cb 100644 --- a/tests/types/test_choice.py +++ b/tests/types/test_choice.py @@ -32,6 +32,10 @@ class TestChoiceType(TestCase): self.User = User + def test_python_type(self): + type_ = self.User.__table__.c.type.type + assert type_.python_type + def test_parameter_processing(self): user = self.User( type=u'admin' diff --git a/tests/types/test_color.py b/tests/types/test_color.py index 59eb512..7165222 100644 --- a/tests/types/test_color.py +++ b/tests/types/test_color.py @@ -18,6 +18,10 @@ class TestColorType(TestCase): self.Document = Document + def test_python_type(self): + type_ = self.Document.__table__.c.bg_color.type + assert type_.python_type == color.colour.Color + def test_color_parameter_processing(self): from colour import Color