@classmethod<EOL><INDENT>def create_ad_hoc_field(cls, db_type):<DEDENT>
import re<EOL>try:<EOL><INDENT>Enum <EOL><DEDENT>except NameError:<EOL><INDENT>from enum import Enum <EOL><DEDENT>members = {}<EOL>for match in re.finditer("<STR_LIT>", db_type):<EOL><INDENT>members[match.group(<NUM_LIT:1>)] = int(match.group(<NUM_LIT:2>))<EOL><DEDENT>enum_cls = Enum('<STR_LIT>', members)<EOL>field_class = Enum8Field if db_type.startswith('<STR_LIT>') else Enum16Field<EOL>return field_class(enum_cls)<EOL>
Give an SQL column description such as "Enum8('apple' = 1, 'banana' = 2, 'orange' = 3)"
this method returns a matching enum field.