Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase or decrease FloatField by 1000 with it's default button?

Tags:

python

django

I have a FloatField in my models. The increase and decrease buttons on the right side of this area normally increase or decrease by 1 each. Is it possible to do this 1000 by 1000? How can I do that?

models.py

class Customer(models.Model):
    ...
    credit_limit = models.FloatField(default=0, null=True)
    ...

forms.py

class NewCustomerForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = ('customer_name', 'country', 'address', 'customer_number', 'phone_number', 'email_address',
                  'credit_limit', 'currency_choice')

to be clear:

to be clear

like image 227
edche Avatar asked Mar 14 '26 11:03

edche


1 Answers

You can make use of the step="…" attribute [w3schools] of the <input type="number"> field, so with:

class NewCustomerForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = …
        widgets = {
            'credit_limit': forms.NumberInput(attrs={'step': 1000})
        }
like image 77
Willem Van Onsem Avatar answered Mar 16 '26 01:03

Willem Van Onsem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!