Last active
June 23, 2025 16:44
-
-
Save rosscdh/f4f26758b0228f475b132c688f15af2b to your computer and use it in GitHub Desktop.
PeeWee JSONField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import peewee as pw | |
| class JSONField(pw.TextField): | |
| """ | |
| Class to "fake" a JSON field with a text field. Not efficient but works nicely | |
| """ | |
| def db_value(self, value): | |
| """Convert the python value for storage in the database.""" | |
| return value if value is None else json.dumps(value) | |
| def python_value(self, value): | |
| """Convert the database value to a pythonic value.""" | |
| return value if value is None else json.loads(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment