forked from ISPsystem/isp-maintenance
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			562 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			562 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import json
 | 
						|
from peewee import TextField
 | 
						|
 | 
						|
 | 
						|
class JSONField(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)
 | 
						|
 | 
						|
 | 
						|
class UnknownField(object):
 | 
						|
    def __init__(self, *_, **__): pass
 |