diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index d7b3558344..6b5233e8de 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -6,6 +6,7 @@ Requires psycopg 2: http://initd.org/projects/psycopg2 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations +from django.utils.safestring import SafeUnicode try: import psycopg2 as Database import psycopg2.extensions @@ -17,6 +18,7 @@ DatabaseError = Database.DatabaseError IntegrityError = Database.IntegrityError psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) +psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString) class DatabaseFeatures(BaseDatabaseFeatures): needs_datetime_string_cast = False diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py index 1132f1ca41..fe80cce406 100644 --- a/tests/modeltests/field_defaults/models.py +++ b/tests/modeltests/field_defaults/models.py @@ -48,4 +48,9 @@ u'Default headline' >>> d = now - a.pub_date >>> d.seconds < 5 True + +# make sure that SafeUnicode fields work +>>> from django.utils.safestring import SafeUnicode +>>> a.headline = SafeUnicode(u'SafeUnicode Headline') +>>> a.save() """}