|
@@ -4,6 +4,7 @@ Custom Django Model Fields.
|
|
|
|
|
|
"""
|
|
|
from django.db import models
|
|
|
+from django.conf import settings
|
|
|
|
|
|
try:
|
|
|
import cPickle as pickle
|
|
@@ -18,6 +19,13 @@ class PickledObject(str):
|
|
|
pass
|
|
|
|
|
|
|
|
|
+if settings.DATABASE_ENGINE == "postgresql_psycopg2":
|
|
|
+ import psycopg2.extensions
|
|
|
+ # register PickledObject as a QuotedString otherwise we will see
|
|
|
+ # can't adapt errors from psycopg2.
|
|
|
+ psycopg2.extensions.register_adapter(PickledObject, psycopg2.extensions.QuotedString)
|
|
|
+
|
|
|
+
|
|
|
class PickledObjectField(models.Field):
|
|
|
"""A field that automatically pickles/unpickles its value."""
|
|
|
__metaclass__ = models.SubfieldBase
|