Django模型的PostgreSQL自定义索引
django-custom-indexes的Python项目详细描述
django自定义索引
==django postgresql后端和自定义字段来创建自定义索引。
这样就无需使用runsql手动编写
迁移以创建索引。
安装
==
[![(https://img.shields.io/pypi/v/django custom index.svg)](https://pypi.org/project/django-custom-indexes/)![](https://img.shields.io/badge/mainted yes green.svg)
![](https://img.shields.io/pypi/djversions/django-custom-index.svg)![](https://img.shields.io/pypi/pyversions/django custom index.svg)
安装:
'django自定义索引'
]
>要求:
>-django 1.7-1.11(未测试2.0+)。
-postgresql数据库后端。
-python 2.7
用法
==
==
使用
www.postggresql.org/docs/9.5/9.5/static/sql createindex.static/sql createindex.html
<更新``引擎``databases``的参数设置为
``django`u custom`index.backends.postgresql`psycopg2``
>默认情况下,custom`u index backend继承自
django.db.backends.postgresql`psycopg2,要使用PostgreSQL psycopg2的其他子类,请添加以下设置:
``django_custom_index_base_engine`
>示例用法:
from django_custom_index import model_fields
from django.db import models
class mymodel(models.model):
my_field1=model_fields.customCharField(
max_length=100,
custom_index=[
{
“unique”:true,可选,用于创建唯一索引
“name”:“custom_unique_index”,可选(自动生成),仅当未指定列时才需要
“where”:“my_field2>;0”,可选,用于创建部分索引
},
{
“unique”:true,
“columns”:[“lower(my_field1)”,可选,为索引指定列或表达式=model_fields.customintegerfield(
自定义索引=[
{
‘名称’:'custom_gin_index1',
‘使用':'using gin(my_field2)’,可选,指定要用于索引的方法
]
==django postgresql后端和自定义字段来创建自定义索引。
这样就无需使用runsql手动编写
迁移以创建索引。
安装
==
[![(https://img.shields.io/pypi/v/django custom index.svg)](https://pypi.org/project/django-custom-indexes/)![](https://img.shields.io/badge/mainted yes green.svg)
![](https://img.shields.io/pypi/djversions/django-custom-index.svg)![](https://img.shields.io/pypi/pyversions/django custom index.svg)
安装:
'django自定义索引'
]
>要求:
>-django 1.7-1.11(未测试2.0+)。
-postgresql数据库后端。
-python 2.7
用法
==
==
使用
www.postggresql.org/docs/9.5/9.5/static/sql createindex.static/sql createindex.html
<更新``引擎``databases``的参数设置为
``django`u custom`index.backends.postgresql`psycopg2``
>默认情况下,custom`u index backend继承自
django.db.backends.postgresql`psycopg2,要使用PostgreSQL psycopg2的其他子类,请添加以下设置:
``django_custom_index_base_engine`
>示例用法:
from django_custom_index import model_fields
from django.db import models
class mymodel(models.model):
my_field1=model_fields.customCharField(
max_length=100,
custom_index=[
{
“unique”:true,可选,用于创建唯一索引
“name”:“custom_unique_index”,可选(自动生成),仅当未指定列时才需要
“where”:“my_field2>;0”,可选,用于创建部分索引
},
{
“unique”:true,
“columns”:[“lower(my_field1)”,可选,为索引指定列或表达式=model_fields.customintegerfield(
自定义索引=[
{
‘名称’:'custom_gin_index1',
‘使用':'using gin(my_field2)’,可选,指定要用于索引的方法
]