对django的postgres复合类型支持
django-postgres-composite-types的Python项目详细描述
django-postgres复合类型
==
postgres[复合类型]的实现(http://www.postgresql.org/docs/current/static/rowtypes.html)
对于[django](https://docs.djangoproject.com/en/1.9/)。
用法
----
pip安装django postgres复合类型
,然后将"postgres复合类型"添加到"已安装的应用程序"中:
其他应用程序
"postgres_composite_types",
]
定义类型并将其添加到模型:
``python
from django.db import models
from postgres_composite_types import compositeype
class address(compositeype):
"一个地址。"
_ 1=型号。字符域(最大长度=255)
地址2=型号。字符域(最大长度=255)
郊区=型号。字符域(最大长度=50)
状态=型号。字符域(最大长度=50)
邮政编码=型号。字符域(最大长度=10)
国家=型号。字符域(最大长度=50)
类元:
db_type='x_address'必需
class person(models.model):
"一个人。"
address=address.field()
`````
o.db import migrations
类迁移(migrations.migration):
operations=[
ld=address.address.field(blank=true,null=true),
],
]
`````
示例
——
>数组字段:
```python
类卡(compositeType):
"扑克牌"。
suit=models.charfield(最大长度=1)
rank=models.charfield(最大长度=2)
class meta:
db-u type='card'
class hand(models.model):
"一手牌"。
cards=arrayfield(base-field=card.field())
````
嵌套类型:
``python
class point(compositeType):
笛卡尔平面。""
pylint:disable=无效名称
x=models.integerfield()
y=models.integerfield()
class meta:
db\u type='x\u point';postgres已经有一个point type
class box(compositeType):
"轴对齐的框"笛卡尔平面。""
类元:
db_type='x_box''postgres已经有一个box type
top_left=point.field()
bottom_right=point.field()
`````
问题和警告*类型的当前*状态,而不是写入迁移时的状态。一般的"createType"操作可以接受该类型的字段,但仍需要手动处理,因为django的"makemigrations"当前不可扩展。
可以使用"rawsql"更改类型,例如:
``python
op操作=[
迁移.runsql([
"alter type x廑address drop attribute country",
"alter type x廑add attribute country integer",
],[
"alter type x廑address drop attribute country",
"alter type x廑add attribute country varchar(50)",
],
]
```
>但是,请注意,如果以前的操作是使用当前的db
代码运行的,那么您已经拥有了正确的类型
([bug 8](https://github.com/danni/django postgres composite types/issues/8))。
避免与将来的PostgreSQL类型冲突的自定义类型。
查找和索引尚未实现hub.com/danni/django postgres composite types/issues/9),
[bug 10](https://github.com/danni/django postgres composite types/issues/10))。
运行测试
----
克隆存储库,转到其基本目录并运行以下命令。
pip install tox
tox
,或者如果您想要特定的环境
tox-e py35-dj2.0
authors
----
*danielle madeley<;danielle@madeley.id.au>;
*tim heap<;hello@timheap.me>;
-
(c)2016,danielle madeley<;danielley@madeley.id.au>;
保留所有权利。
源代码的重新分发必须保留上述版权声明、此条件列表和以下免责声明。
2.二进制形式的再分配必须复制上述版权声明,
此条件列表和文档中的以下免责声明
和/或与再分配一起提供的其他材料。
3.未经事先书面许可,版权所有人的姓名或其贡献者的姓名均不得用于认可或推广由本软件衍生的产品。
明示或默示保证,包括但不限于对适销性和特定用途适用性的默示
保证,概不负责。在任何情况下,版权持有人或贡献者均不对任何直接、间接、附带、特殊、惩戒性或后果性损害(包括但不限于购买替代品或服务;使用、数据或利润损失;或业务中断)承担责任。er
由本软件使用过程中以任何方式产生的任何责任理论(无论是合同责任、严格责任、侵权行为(包括疏忽或其他)引起,即使已告知此类损害的可能性。
==
postgres[复合类型]的实现(http://www.postgresql.org/docs/current/static/rowtypes.html)
对于[django](https://docs.djangoproject.com/en/1.9/)。
用法
----
pip安装django postgres复合类型
,然后将"postgres复合类型"添加到"已安装的应用程序"中:
其他应用程序
"postgres_composite_types",
]
定义类型并将其添加到模型:
``python
from django.db import models
from postgres_composite_types import compositeype
class address(compositeype):
"一个地址。"
_ 1=型号。字符域(最大长度=255)
地址2=型号。字符域(最大长度=255)
郊区=型号。字符域(最大长度=50)
状态=型号。字符域(最大长度=50)
邮政编码=型号。字符域(最大长度=10)
国家=型号。字符域(最大长度=50)
类元:
db_type='x_address'必需
class person(models.model):
"一个人。"
address=address.field()
`````
o.db import migrations
类迁移(migrations.migration):
operations=[
ld=address.address.field(blank=true,null=true),
],
]
`````
示例
——
>数组字段:
```python
类卡(compositeType):
"扑克牌"。
suit=models.charfield(最大长度=1)
rank=models.charfield(最大长度=2)
class meta:
db-u type='card'
class hand(models.model):
"一手牌"。
cards=arrayfield(base-field=card.field())
````
嵌套类型:
``python
class point(compositeType):
笛卡尔平面。""
pylint:disable=无效名称
x=models.integerfield()
y=models.integerfield()
class meta:
db\u type='x\u point';postgres已经有一个point type
class box(compositeType):
"轴对齐的框"笛卡尔平面。""
类元:
db_type='x_box''postgres已经有一个box type
top_left=point.field()
bottom_right=point.field()
`````
问题和警告*类型的当前*状态,而不是写入迁移时的状态。一般的"createType"操作可以接受该类型的字段,但仍需要手动处理,因为django的"makemigrations"当前不可扩展。
可以使用"rawsql"更改类型,例如:
``python
op操作=[
迁移.runsql([
"alter type x廑address drop attribute country",
"alter type x廑add attribute country integer",
],[
"alter type x廑address drop attribute country",
"alter type x廑add attribute country varchar(50)",
],
]
```
>但是,请注意,如果以前的操作是使用当前的db
代码运行的,那么您已经拥有了正确的类型
([bug 8](https://github.com/danni/django postgres composite types/issues/8))。
避免与将来的PostgreSQL类型冲突的自定义类型。
查找和索引尚未实现hub.com/danni/django postgres composite types/issues/9),
[bug 10](https://github.com/danni/django postgres composite types/issues/10))。
运行测试
----
克隆存储库,转到其基本目录并运行以下命令。
pip install tox
tox
,或者如果您想要特定的环境
tox-e py35-dj2.0
authors
----
*danielle madeley<;danielle@madeley.id.au>;
*tim heap<;hello@timheap.me>;
-
(c)2016,danielle madeley<;danielley@madeley.id.au>;
保留所有权利。
源代码的重新分发必须保留上述版权声明、此条件列表和以下免责声明。
2.二进制形式的再分配必须复制上述版权声明,
此条件列表和文档中的以下免责声明
和/或与再分配一起提供的其他材料。
3.未经事先书面许可,版权所有人的姓名或其贡献者的姓名均不得用于认可或推广由本软件衍生的产品。
明示或默示保证,包括但不限于对适销性和特定用途适用性的默示
保证,概不负责。在任何情况下,版权持有人或贡献者均不对任何直接、间接、附带、特殊、惩戒性或后果性损害(包括但不限于购买替代品或服务;使用、数据或利润损失;或业务中断)承担责任。er
由本软件使用过程中以任何方式产生的任何责任理论(无论是合同责任、严格责任、侵权行为(包括疏忽或其他)引起,即使已告知此类损害的可能性。