Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 django-money,它为我提供了我在项目中经常使用的 MoneyField。但是 MoneyField 期望总是有 max_digits 选项。如何为此类字段设置默认值以避免一直键入它并在以后更糟地维护它?
制作您自己的派生自MoneyField. 然后使用该类而不是MoneyField.
MoneyField
例如:
DEFAULT_MAX_DIGITS = 10 class MyMoneyField(MoneyField): def __init__(self, *args, **kwargs): kwargs['max_digits'] = kwargs.pop('max_digits', DEFAULT_MAX_DIGITS) super(MyMoneyField, self).__init__(*args, **kwargs)