mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #5996 -- Add a pyscopg2 convertor for SafeUnicode -> unicode. Thanks, remco@diji.biz
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6816 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b3db18817a
commit
348f2cbfc1
@ -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
|
||||
|
@ -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()
|
||||
"""}
|
||||
|
Loading…
Reference in New Issue
Block a user