Add docs for IPAddressType
This commit is contained in:
@@ -56,7 +56,7 @@ class CountryType(types.TypeDecorator, ScalarCoercible):
|
|||||||
|
|
||||||
|
|
||||||
user = User()
|
user = User()
|
||||||
user.working_days = Country('FI')
|
user.country = Country('FI')
|
||||||
session.add(user)
|
session.add(user)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
@@ -64,6 +64,13 @@ class CountryType(types.TypeDecorator, ScalarCoercible):
|
|||||||
user.country.name # Finland
|
user.country.name # Finland
|
||||||
|
|
||||||
print user.country # Finland
|
print user.country # Finland
|
||||||
|
|
||||||
|
|
||||||
|
CountryType is scalar coercible::
|
||||||
|
|
||||||
|
|
||||||
|
user.country = 'US'
|
||||||
|
user.country # Country('US')
|
||||||
"""
|
"""
|
||||||
impl = types.String(2)
|
impl = types.String(2)
|
||||||
python_type = Country
|
python_type = Country
|
||||||
|
@@ -19,6 +19,32 @@ class IPAddressType(types.TypeDecorator, ScalarCoercible):
|
|||||||
"""
|
"""
|
||||||
Changes IPAddress objects to a string representation on the way in and
|
Changes IPAddress objects to a string representation on the way in and
|
||||||
changes them back to IPAddress objects on the way out.
|
changes them back to IPAddress objects on the way out.
|
||||||
|
|
||||||
|
IPAddressType uses ipaddress package on Python >= 3 and ipaddr_ package on
|
||||||
|
Python 2. In order to use IPAddressType with python you need to install
|
||||||
|
ipaddr_ first.
|
||||||
|
|
||||||
|
.. _ipaddr: https://pypi.python.org/pypi/ipaddr
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
|
||||||
|
from sqlalchemy_utils import IPAddressType
|
||||||
|
|
||||||
|
|
||||||
|
class User(Base):
|
||||||
|
__tablename__ = 'user'
|
||||||
|
id = sa.Column(sa.Integer, autoincrement=True)
|
||||||
|
name = sa.Column(sa.Unicode(255))
|
||||||
|
ip_address = sa.Column(IPAddressType)
|
||||||
|
|
||||||
|
|
||||||
|
user = User()
|
||||||
|
user.ip_address = '123.123.123.123'
|
||||||
|
session.add(user)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
user.ip_address # IPAddress object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
impl = types.Unicode(50)
|
impl = types.Unicode(50)
|
||||||
|
Reference in New Issue
Block a user