Default value for field in Django model

前端 未结 3 817
长发绾君心
长发绾君心 2020-12-02 08:58

Suppose I have a model:

class SomeModel(models.Model):
    id = models.AutoField(primary_key=True)
    a = models.CharField(max_length=10)
    b = models.Cha         


        
3条回答
  •  清歌不尽
    2020-12-02 09:17

    You can also use a callable in the default field, such as:

    b = models.CharField(max_length=7, default=foo)
    

    And then define the callable:

    def foo():
        return 'bar'
    

提交回复
热议问题