class MyCharField(models.Field):
    def __init__(self,max_length,*args,**kwargs):
        self.max_length = max_length
        super().__init__(max_length=max_length,*args,**kwargs)

    def db_type(self, connection):
        return 'char(%s)'%self.max_length

class Product(models.Model):
    name = models.CharField(max_length=32)  # 都是类实例化出来的对象
    price = models.DecimalField(max_digits=8,decimal_places=2)
    maichu = models.IntegerField()
    kucun = models.IntegerField()
    #使用自定义的字段
    info = MyCharField(max_length=32,null=True)  # 改字段可以为空



choices = ((1,''),(2,''),(3,'其他')) gender = models.IntegerField(choices=choices,default=2)

 

相关文章:

  • 2021-09-05
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2021-06-16
  • 2022-12-23
猜你喜欢
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2021-11-23
  • 2021-09-01
相关资源
相似解决方案