2014-03-15 01:34:49 +08:00
|
|
|
from django.apps import AppConfig
|
2016-07-20 16:18:11 +08:00
|
|
|
from django.db import connections
|
2014-03-15 01:34:49 +08:00
|
|
|
from django.db.backends.signals import connection_created
|
2014-09-06 04:53:11 +08:00
|
|
|
from django.db.models import CharField, TextField
|
2017-01-27 03:58:33 +08:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2014-03-15 01:34:49 +08:00
|
|
|
|
2015-06-06 00:37:48 +08:00
|
|
|
from .lookups import SearchLookup, TrigramSimilar, Unaccent
|
2017-05-03 13:25:30 +08:00
|
|
|
from .signals import register_type_handlers
|
2014-03-15 01:34:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PostgresConfig(AppConfig):
|
|
|
|
name = 'django.contrib.postgres'
|
|
|
|
verbose_name = _('PostgreSQL extensions')
|
|
|
|
|
|
|
|
def ready(self):
|
2016-07-20 16:18:11 +08:00
|
|
|
# Connections may already exist before we are called.
|
|
|
|
for conn in connections.all():
|
2017-09-09 20:39:09 +08:00
|
|
|
if conn.vendor == 'postgresql':
|
|
|
|
conn.introspection.data_types_reverse.update({
|
|
|
|
3802: 'django.contrib.postgresql.fields.JSONField',
|
|
|
|
})
|
|
|
|
if conn.connection is not None:
|
|
|
|
register_type_handlers(conn)
|
2017-05-03 13:25:30 +08:00
|
|
|
connection_created.connect(register_type_handlers)
|
2014-09-06 04:53:11 +08:00
|
|
|
CharField.register_lookup(Unaccent)
|
|
|
|
TextField.register_lookup(Unaccent)
|
2015-06-01 05:45:03 +08:00
|
|
|
CharField.register_lookup(SearchLookup)
|
|
|
|
TextField.register_lookup(SearchLookup)
|
2015-06-06 00:37:48 +08:00
|
|
|
CharField.register_lookup(TrigramSimilar)
|
|
|
|
TextField.register_lookup(TrigramSimilar)
|