I have a form input on body height. I would like to put 'cm' after the height number (e.g. 183cm instead of just selecting 183) but keep it as a NumberInput.
Is it possible to add the suffix in the widget?
I have the following form.py:
from django import forms
from .models import Account
class RegistrationForm(forms.ModelForm):
body_height = forms.NumberInput(attrs={'min':120,'max':230,'step':1, 'required':False,})
class Meta:
model = Account
fields = ['body_height','otherfields']
def __init__(self, *args, **kwargs):
self.fields['body_height'].widget.attrs['placeholder'] = 'Your height (centimeters)'
You can extend the default
NumberInput's render method and change the default Html.