Or tuples (used as value, description) or EnumSymbols. Reg.sort(key=lambda k: reg._creation_order)Īttributes can be strings (used as values), Return iter()Įlif isinstance(v, tuple) and len(v) = 2: """Allow unpickling to return the symbol linked to the DeclEnum class.""" """Define a fixed symbol tied to a parent class."""ĭef _init_(self, value, description=None): Here is the modified recipe it uses the OrderedDict class available in Python 2.7: import reįrom sqlalchemy.types import SchemaType, TypeDecorator, Enumįrom sqlalchemy.util import set_creation_order, OrderedDict # order will be as stated: full_time, part_time, contractor # order will be alphabetic: contractor, part_time, full_time So I changed the order to be alphabetic if you set the attributes as strings or tuples, or the order in which the values are declared if you explicitly set the attributes as EnumSymbols - this is using the same trick as SQLAlchemy does when it orders the Columns in DeclarativeBase classes. But often I want to have a determinate order.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |