Add some docs for WeekDaysType
This commit is contained in:
@@ -14,6 +14,7 @@ ArrowType
|
||||
|
||||
.. autoclass:: ArrowType
|
||||
|
||||
|
||||
ChoiceType
|
||||
^^^^^^^^^^
|
||||
|
||||
|
@@ -34,6 +34,7 @@ class LocaleType(types.TypeDecorator, ScalarCoercible):
|
||||
|
||||
user = User()
|
||||
user.locale = Locale('en_US')
|
||||
session.add(user)
|
||||
session.commit()
|
||||
|
||||
|
||||
|
@@ -6,6 +6,46 @@ from .bit import BitType
|
||||
|
||||
|
||||
class WeekDaysType(types.TypeDecorator, ScalarCoercible):
|
||||
"""
|
||||
WeekDaysType offers way of saving WeekDays objects into database. The
|
||||
WeekDays objects are converted to bit strings on the way in and back to
|
||||
WeekDays objects on the way out.
|
||||
|
||||
In order to use WeekDaysType you need to install Babel_ first.
|
||||
|
||||
.. _Babel: http://babel.pocoo.org/
|
||||
|
||||
::
|
||||
|
||||
|
||||
from sqlalchemy_utils import WeekDaysType, WeekDays
|
||||
from babel import Locale
|
||||
|
||||
|
||||
class Schedule(Base):
|
||||
__tablename__ = 'schedule'
|
||||
id = sa.Column(sa.Integer, autoincrement=True)
|
||||
working_days = sa.Column(WeekDaysType)
|
||||
|
||||
|
||||
schedule = Schedule()
|
||||
schedule.working_days = WeekDays('0001111')
|
||||
session.add(schedule)
|
||||
session.commit()
|
||||
|
||||
print schedule.working_days # Thursday, Friday, Saturday, Sunday
|
||||
|
||||
|
||||
WeekDaysType also supports scalar coercion:
|
||||
|
||||
::
|
||||
|
||||
|
||||
schedule.working_days = '1110000'
|
||||
schedule.working_days # WeekDays object
|
||||
|
||||
"""
|
||||
|
||||
impl = BitType(WeekDay.NUM_WEEK_DAYS)
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
|
@@ -1,11 +1,17 @@
|
||||
from babel import Locale
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy_utils.types import WeekDaysType
|
||||
from sqlalchemy_utils.primitives import WeekDays
|
||||
from sqlalchemy_utils import i18n
|
||||
|
||||
from tests import TestCase
|
||||
|
||||
|
||||
class WeekDaysTypeTestCase(TestCase):
|
||||
def setup_method(self, method):
|
||||
TestCase.setup_method(self, method)
|
||||
i18n.get_locale = lambda: Locale('en')
|
||||
|
||||
def create_models(self):
|
||||
class Schedule(self.Base):
|
||||
__tablename__ = 'schedule'
|
||||
|
Reference in New Issue
Block a user