diff --git a/docs/data_types.rst b/docs/data_types.rst index 916fd78..3e59eec 100644 --- a/docs/data_types.rst +++ b/docs/data_types.rst @@ -31,6 +31,14 @@ ColorType .. autoclass:: ColorType +CountryType +^^^^^^^^^^^ + +.. module:: sqlalchemy_utils.types.country + +.. autoclass:: CountryType + + JSONType ^^^^^^^^ diff --git a/sqlalchemy_utils/types/country.py b/sqlalchemy_utils/types/country.py index b05fe0c..5032cc8 100644 --- a/sqlalchemy_utils/types/country.py +++ b/sqlalchemy_utils/types/country.py @@ -37,8 +37,34 @@ class CountryType(types.TypeDecorator, ScalarCoercible): """ Changes Country objects to a string representation on the way in and changes them back to Country objects on the way out. - """ + In order to use CountryType you need to install Babel_ first. + + .. _Babel: http://babel.pocoo.org/ + + :: + + + from sqlalchemy_utils import CountryType, Country + + + class User(Base): + __tablename__ = 'user' + id = sa.Column(sa.Integer, autoincrement=True) + name = sa.Column(sa.Unicode(255)) + country = sa.Column(CountryType) + + + user = User() + user.working_days = Country('FI') + session.add(user) + session.commit() + + user.country # Country('FI') + user.country.name # Finland + + print user.country # Finland + """ impl = types.String(2) python_type = Country