Permalink
Browse files

Multi DB support

Add 'connection' argument to fields.YAMLField.get_db_prep_save.  Eliminate
extraneous whitespace.
  • Loading branch information...
1 parent f9506f5 commit 2e5a21b80f13389a99241a6943b42556556bff96 @btubbs btubbs committed Apr 2, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 yamlfield/fields.py
View
@@ -7,12 +7,12 @@ class YAMLField(models.TextField):
"""
YAMLField is a TextField that serializes and deserializes YAML data
from the database.
-
+
Based on https://github.com/bradjasper/django-jsonfield
"""
# Used so to_python() is called
__metaclass__ = models.SubfieldBase
-
+
def to_python(self, value):
"""
Convert our YAML string to a Python object after we load it from the DB.
@@ -25,22 +25,22 @@ def to_python(self, value):
except ValueError:
pass
return value
-
- def get_db_prep_save(self, value):
+
+ def get_db_prep_save(self, value, connection, prepared=False):
"""
Convert our Python object to a string of YAML before we save.
"""
if not value or value == "":
return ""
if isinstance(value, (dict, list)):
- value = yaml.dump(value, Dumper=DjangoSafeDumper,
+ value = yaml.dump(value, Dumper=DjangoSafeDumper,
default_flow_style=False)
- return super(YAMLField, self).get_db_prep_save(value)
-
+ return super(YAMLField, self).get_db_prep_save(value, connection)
+
def value_from_object(self, obj):
"""
Returns the value of this field in the given model instance.
-
+
We need to override this so that the YAML comes out properly formatted
in the admin widget.
"""

0 comments on commit 2e5a21b

Please sign in to comment.