Search code examples
djangofielddefaultmodels

Django default value


If I create a field as typed below, will the default value be saved to the object, when the field on the form leaved blank?

field_name = models.FloatField(default=100.0, blank=True)

Solution

  • About default for model field :

    The default value is used when new model instances are created and a value isn’t provided for the field. When the field is a primary key, the default is also used when the field is set to None.

    https://docs.djangoproject.com/en/1.10/ref/models/fields/#default