mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-16 00:23:10 +00:00
18 lines
655 B
Python
18 lines
655 B
Python
from django.conf import settings
|
|
|
|
|
|
class PostgresRouter(object):
|
|
@staticmethod
|
|
def in_postgres(model):
|
|
app_label = model._meta.app_label
|
|
model_name = model._meta.model_name
|
|
return app_label == 'cachalot' and model_name == 'postgresmodel'
|
|
|
|
def get_postgresql_alias(self):
|
|
return ('postgresql' if 'postgresql' in settings.DATABASES
|
|
else 'default')
|
|
|
|
def allow_migrate(self, db, app_label, model=None, **hints):
|
|
if hints.get('extension') in ('hstore', 'unaccent') \
|
|
or (model is not None and self.in_postgres(model)):
|
|
return db == self.get_postgresql_alias()
|