custom model field

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class Sample(models.Field):
def db_type(self):
return 'datetime'
class SimpleTest(models.Model):
xxx = Sample()
#######################################################
class Sample(models.Field):
def __init__(self, max_length, *args, **kwargs):
self.max_length = max_length
super(Sample, self).__init__(*args, **kwargs)
def db_type(self):
return 'varchar(%s)' % self.max_length
class SimpleTest(models.Model):
xxx = Sample(25)