How can I store a Python Enum using Pony ORM? How can I store a Python Enum using Pony ORM? python-3.x python-3.x

How can I store a Python Enum using Pony ORM?


Excerpt from some random mailing list:

2.2. CONVERTER METHODS

Each converter class should define the following methods:

class MySpecificConverter(Converter):    def init(self, kwargs):        # Override this method to process additional positional        # and keyword arguments of the attribute       if self.attr is not None:            # self.attr.args can be analyzed here            self.args = self.attr.args        self.my_optional_argument = kwargs.pop("kwarg_name")        # You should take all valid options from this kwargs        # What is left in is regarded as unrecognized option    def validate(self, val):        # convert value to the necessary type (e.g. from string)        # validate all necessary constraints (e.g. min/max bounds)        return val    def py2sql(self, val):        # prepare the value (if necessary) to storing in the database        return val    def sql2py(self, value):        # convert value (if necessary) after the reading from the db        return val    def sql_type(self):        # generate corresponding SQL type, based on attribute options        return "SOME_SQL_TYPE_DEFINITION"

You can study the code of the existing converters to see how these methods are implemented.