3

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

edche
  • 636
  • 6
  • 33
  • Try to use `step`, check this https://stackoverflow.com/questions/27949510/django-float-field-input – Nick Aug 11 '21 at 08:19

1 Answers1

1

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})
        }
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555