I'm trying to create a DecimalField subclass, using the code below
class PositiveMoneyField(DecimalField):
def __init__(self, verbose_name=None, name=None, **kwargs):
super().__init__(self,
verbose_name, name,
max_digits=9, decimal_places=2,
validators=[MinValueValidator(Decimal(0.0)), ],
**kwargs
)
But it give me this error:
TypeError: __init__() got multiple values for argument 'max_digits'
Any help is appreciated.
Thanks,
Eric
After checking other django fields as SlugField, I found the solution:
class PositiveMoneyField(DecimalField):
def __init__(self, *args, max_digits=9, decimal_places=2, **kwargs):
kwargs.update({'validators': [MinValueValidator(Decimal(0.01)), ]})
super().__init__(*args, max_digits=max_digits, decimal_places=decimal_places, **kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With