1 # 时间戳字段
2 class TimeStampField(Field):
3 db_field = ‘timestamp‘
4
5 class SmallIntegerField(IntegerField):
6 db_field = ‘smallint‘
7
8 class PasswordField(FixedCharField):
9
10 def __init__(self, *args, **kwargs):
11 self.max_length =64
12 super(PasswordField, self).__init__(max_length=self.max_length, *args, **kwargs)
13
14 def db_value(self, value):
15 return encrypt(value)
16
17 def python_value(self, value):
18 return encrypt(value)
19 # 性别字段
20 class GenderField(Field):
21 db_field = ‘enum("f", "m")‘
1 class Base(Model):
2 class Meta:
3 database = db
4
5 class Person(Base):
6 name = CharField(max_length=20, default=‘haha‘)
7 intro = TextField(default=‘‘)
8 birth = DateTimeField(default=datetime.now())
9 Married = BooleanField(default=False)
10 height = FloatField(default=0)
11 wight = DoubleField(default=0)
12 salary = DecimalField(default=0)
13 Save = BigIntegerField(default=0)
14 family = SmallIntegerField(default=0)
15 age = IntegerField(default=0)
16 username = CharField(max_length=20)
17 password = PasswordField(default=‘‘)
18 ctime = TimeStampField()
19 today = DateField(default=datetime.date(datetime.today()))
20 now = TimeField(default=datetime.today())
21 secret = BlobField(default=‘‘)
22 gender = GenderField()