Skip to main content
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
============

[![](https://img.shields.io/pypi/v/django-custom-indexes.svg)](https://pypi.org/project/django-custom-indexes/) ![](https://img.shields.io/badge/Maintained-yes-green.svg)
![](https://img.shields.io/pypi/djversions/django-custom-indexes.svg) ![](https://img.shields.io/pypi/pyversions/django-custom-indexes.svg)
Installation:


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.11 (not tested for 2.0+).
- 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
}
]
)



Metadata

Release files for django-custom-indexes 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-custom-indexes 0.1.5
File Size Uploaded
django-custom-indexes-0.1.5.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-custom-indexes 0.1.5
File Interpreter ABI Platform
django_custom_indexes-0.1.5-py2-none-any.whl Python 2 none any Details

Total release size: 11.5 kB

Release files / django-custom-indexes-0.1.5.tar.gz

Download URL django-custom-indexes-0.1.5.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b76d37fc1818ec9deb7b49a788c086973c4c5d858422621f50d23515671bf88b
BLAKE2b-256 checksum
How to use checksums
a7d334359f8ec0822a7332c573ddbb38b3d8b17f30b1d704a8ea3ebbd94754aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.5.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.13

Release files / django_custom_indexes-0.1.5-py2-none-any.whl

Download URL django_custom_indexes-0.1.5-py2-none-any.whl
Size 7.6 kB
Tags Python 2
SHA-256 checksum
How to use checksums
bc4e487c40074e945a3e11f835dad91a74311e2beb1ff1c747573a65967bea01
BLAKE2b-256 checksum
How to use checksums
90a55c19df8276867f1ff2664d4652a76d5a462422a2938b334fc1d39e9ff37a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.5.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.13

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page