You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
860 B

  1. from psycopg2 import ProgrammingError
  2. from psycopg2.extras import register_hstore
  3. from django.utils import six
  4. def register_hstore_handler(connection, **kwargs):
  5. if connection.vendor != 'postgresql':
  6. return
  7. try:
  8. if six.PY2:
  9. register_hstore(connection.connection, globally=True, unicode=True)
  10. else:
  11. register_hstore(connection.connection, globally=True)
  12. except ProgrammingError:
  13. # Hstore is not available on the database.
  14. #
  15. # If someone tries to create an hstore field it will error there.
  16. # This is necessary as someone may be using PSQL without extensions
  17. # installed but be using other features of contrib.postgres.
  18. #
  19. # This is also needed in order to create the connection in order to
  20. # install the hstore extension.
  21. pass