Created
December 7, 2011 03:18
-
-
Save longfin/1441283 to your computer and use it in GitHub Desktop.
Class Factory?
This file contains 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
TAG_TYPES = ["location", "category"] | |
class Tag(db.Model, BaseEntityMixIn, | |
IgnoreDeletionMixIn): | |
__tablename__ = "tag" | |
name = db.Column(db.Unicode(255), index=True) | |
type = db.Column(db.Enum(*TAG_TYPES, native_enum=False), index=True) | |
__mapper_args__ = {'polymorphic_on': type} | |
g = globals() | |
for t in TAG_TYPES: | |
def __init__(self, t=t, **kwargs): | |
kwargs["type"] = t | |
Tag.__init__(self, **kwargs) | |
cls_name = t.capitalize()+"Tag" | |
cls = type(cls_name, (Tag,), {'__tablename__':None, | |
'__mapper_args__': {'polymorphic_identity' : t}, | |
'__init__': __init__}) | |
g[cls_name] = cls |
SAWarning이 거슬려서 type()을 쓰게끔 대대적으로 변경...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/1441484 이런 짓을 하면... 안되겠죠 =3