Skip to content

Commit

Permalink
fix: Fix persisting data to strings for the JSONField after a Django …
Browse files Browse the repository at this point in the history
…1.9 change.
  • Loading branch information
skorokithakis committed Oct 6, 2016
1 parent bacd5bd commit 919463e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions annoying/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class Page(models.Model):
"""

def to_python(self, value):
"""
Convert a string from the database to a Python value.
"""
if value == "":
return None

Expand All @@ -122,6 +125,12 @@ def to_python(self, value):
pass
return value

def get_prep_value(self, value):
"""
Convert the value to a string so it can be stored in the database.
"""
return self.get_db_prep_save(value)

This comment has been minimized.

Copy link
@guoqiao

guoqiao Oct 7, 2016

This will trigger an error, since the get_db_prep_save method requires a second connection positional arg.

This comment has been minimized.

Copy link
@skorokithakis

skorokithakis Oct 7, 2016

Author Owner

Ah, damnit. Thanks, although I don't know why it worked locally... I'll fix it now.


def from_db_value(self, value, *args, **kwargs):
return self.to_python(value)

Expand Down

0 comments on commit 919463e

Please sign in to comment.