PostgreSQL custom indexes for Django models
Project description
django-custom-indexes
Django PostgreSQL backend and custom fields to create custom indexes.
With this, indexes can be defined for a model using field attributes which will be migrated to the db, this eliminates the need to write migrations manually with RunSQL to create indexes.
Installation
This app is available on PyPI and can be installed with:
pip install django-custom-indexes
PyPI: https://pypi.python.org/pypi/django-custom-indexes/
Add django_custom_indexes to your INSTALLED_APPS:
INSTALLED_APPS = ( '...', 'django_custom_indexes' )
Requirements:
Django 1.7 to 1.10 (1.11 already has support for defining indexes in models using Meta class).
PostgreSQL database backend.
Python 2.7
Usage
Creating Indexes in PostgresSQL: https://www.postgresql.org/docs/9.5/static/sql-createindex.html
In your settings update the ENGINE parameter of DATABASES to 'django_custom_indexes.backends.postgresql_psycopg2'
By default custom_indexes backend inherits from django.db.backends.postgresql_psycopg2, to use some other sub class of postgresql_psycopg2 add the following setting:
DJANGO_CUSTOM_INDEXES_BASE_ENGINE
Example Usage:
from django_custom_indexes import model_fields from django.db import models class MyModel(models.Model): my_field1 = model_fields.CustomCharField( max_length=100, custom_indexes=[ { 'unique': True, # Optional, used to create unique indexes 'name': 'custom_unique_index', # Optional (auto generated), Required only if no columns are specified 'where': 'my_field2 > 0', # Optional, used to create partial Indexes }, { 'unique': True, 'columns': ['lower(my_field1)'], # Optional, Specify columns or expressions for the index } ] ) my_field2 = model_fields.CustomIntegerField( custom_indexes=[ { 'name': 'custom_gin_index1', 'using': 'USING gin (my_field2)', # Optional, Specify which method to use for the index } ] )
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-custom-indexes-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30d3a9ab5b2ac8f1a060e671473dcf7ed71182bdf347f0638efa3aeb0ba76fa5 |
|
MD5 | 1e65dc553c2a87735ceefac90d2a25a1 |
|
BLAKE2b-256 | 8f5f6656f717f6a3dd8086f9f3ed260e1734b03569af25c6687792061b9c485e |
Hashes for django_custom_indexes-0.1.4-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fb2e30205f44be1b98ed284242a8df242bf81f4e96f5359345a58d153816bed |
|
MD5 | b6fc6b423d98db3bb20a161b6d118e80 |
|
BLAKE2b-256 | 51887d1acaa99f999d8e6f800d769137e8954440a9559bb8d4c226291f28e101 |