diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2017-12-05 09:43:56 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-08-02 10:39:18 -0400 |
| commit | d526b07784d8caa208055c1f2bd1cedc88fb52dc (patch) | |
| tree | 884e5bc8f02320833854f393715049ab5a7da4ab /django | |
| parent | 2092206bee3281e6809a8fddb5230d80902a02b4 (diff) | |
Fixed #26974 -- Added HashIndex to django.contrib.postgres.
Thanks Akshesh Doshi for the initial implementation.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/postgres/indexes.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py index 677c63b4a2..3b77b97f3e 100644 --- a/django/contrib/postgres/indexes.py +++ b/django/contrib/postgres/indexes.py @@ -1,7 +1,7 @@ from django.db.models import Index from django.utils.functional import cached_property -__all__ = ['BrinIndex', 'GinIndex', 'GistIndex'] +__all__ = ['BrinIndex', 'GinIndex', 'GistIndex', 'HashIndex'] class PostgresIndex(Index): @@ -98,3 +98,23 @@ class GistIndex(PostgresIndex): if self.fillfactor is not None: with_params.append('fillfactor = %d' % self.fillfactor) return with_params + + +class HashIndex(PostgresIndex): + suffix = 'hash' + + def __init__(self, *, fillfactor=None, **kwargs): + self.fillfactor = fillfactor + super().__init__(**kwargs) + + def deconstruct(self): + path, args, kwargs = super().deconstruct() + if self.fillfactor is not None: + kwargs['fillfactor'] = self.fillfactor + return path, args, kwargs + + def get_with_params(self): + with_params = [] + if self.fillfactor is not None: + with_params.append('fillfactor = %d' % self.fillfactor) + return with_params |
