假设我的对象具有DecimalField默认设置为20. 当我在 python 中创建一个对象并且没有为它指定一个值时DecimalField,它是None.
如何确保每次我不提供值时都应用默认值?
class SomeModel(models.Model):
"""Demonstrate the flaw of the default value."""
dec_field = models.DecimalField(default=1, blank=True, null=True)
my_model = SomeModel()
my_model.save() # this is where I expect the dec_field to become Decimal('1.0')
# instead it's None