Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshtechnologygroup/django-custom-indexes
Django PostgreSQL backend and custom fields to define custom indexes using field attributes.
https://github.com/joshtechnologygroup/django-custom-indexes
db-backend django django-application postgresql psycopg2-extension python27
Last synced: 3 months ago
JSON representation
Django PostgreSQL backend and custom fields to define custom indexes using field attributes.
- Host: GitHub
- URL: https://github.com/joshtechnologygroup/django-custom-indexes
- Owner: joshtechnologygroup
- License: bsd-3-clause
- Created: 2017-09-21T18:38:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-22T11:32:04.000Z (about 6 years ago)
- Last Synced: 2024-10-16T01:04:06.696Z (4 months ago)
- Topics: db-backend, django, django-application, postgresql, psycopg2-extension, python27
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
- License: LICENSE.txt
Awesome Lists containing this project
README
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://pypi.org/project/django-custom-indexes/) [![](https://img.shields.io/pypi/djversions/django-custom-indexes.svg)](https://pypi.org/project/django-custom-indexes/) [![](https://img.shields.io/pypi/pyversions/django-custom-indexes.svg)](https://pypi.org/project/django-custom-indexes/)
The package can be installed by running the following command:
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.7Usage
=====Creating Indexes in PostgresSQL:
https://www.postgresql.org/docs/9.5/static/sql-createindex.htmlIn 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 modelsclass 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
}
]
)