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
|
2014-03-15 01:34:49 +08:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2015-06-06 00:37:48 +08:00
|
|
|
from .lookups import SearchLookup, TrigramSimilar, Unaccent
|
2014-03-15 01:34:49 +08:00
|
|
|
from .signals import register_hstore_handler
|
|
|
|
|
|
|
|
|
|
|
|
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():
|
|
|
|
if conn.connection is not None:
|
|
|
|
register_hstore_handler(conn)
|
2014-03-15 01:34:49 +08:00
|
|
|
connection_created.connect(register_hstore_handler)
|
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)
|