classtype(object): def__init__(cls, what, bases=None, dict=None):# known special case of type.__init__ """ type(object_or_name, bases, dict) type(object) -> the object's type type(name, bases, dict) -> a new type # (copied from class doc) """ pass
primarykeys = [] for k, v in attrs.items(): ifisinstance(v, Field): print(k) print(v) print(v.fieldname) if v.fieldname isNone: v.fieldname = k # 没有名字则使用属性名 if v.pk: primarykeys.append(v)
attrs['__primarykeys__'] = primarykeys
returnsuper().__new__(cls, name, bases, attrs)
classModelBase(metaclass=ModelMeta): pass
classStudent(ModelBase): id = Field(pk=True, nullable=False) name = Field('username', nullable=False) age = Field()