Skip to main content

PostgreSQL custom indexes for Django models

Project description


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.


[![](]( ![](
![]( ![](

pip install django-custom-indexes


Add ``django_custom_indexes`` to your ``INSTALLED_APPS``:



- Django 1.7 to 1.11 (not tested for 2.0+).
- PostgreSQL database backend.
- Python 2.7


Creating Indexes in PostgresSQL:

In your settings update the ``ENGINE`` parameter of ``DATABASES`` to

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:


Example Usage:

from django_custom_indexes import model_fields
from django.db import models

class MyModel(models.Model):
my_field1 = model_fields.CustomCharField(
'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(
'name': 'custom_gin_index1',
'using': 'USING gin (my_field2)', # Optional, Specify which method to use for the index

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_custom_indexes-0.1.5-py2-none-any.whl (7.6 kB) Copy SHA256 hash SHA256 Wheel py2
django-custom-indexes-0.1.5.tar.gz (4.0 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page