Help with Number Formatting in Django 1.9

1

Hello I have the following problem, I am trying to format numbers with the help of the library jquery-number , the problem is that when I want to assign its properties to the input, I do not achieve it since at the moment of placing said field in the following way {{ form.precio_c }} and I do not know how to entangle it the properties of that library to format the number.

I tried to put it in div but it does not work. or is there another way to do it?

What I want to achieve is if I put a number example: 12000 to format it this way 12,000.00

greetings ..

my code is like that ..

<div class="input-field col s3 m3" >
  {{ form.precio_c }}
  <label for="last_name">{{ form.precio_c.label }}</label>
</div>

library properties

id="price" name="number"
    
asked by wootsbot 21.04.2016 в 20:18
source

1 answer

2

The classes and attributes of the elements of a form, if you want to use the form object, you must place them in the class that creates the form. In your case, use a field form.DecimalField and a widget NumberInput .

from .models import Precio
from django import forms

class PrecioForm(forms.ModelForm):
    class Meta:
        model = Precio
        exclude = []

    precio_c = forms.DecimalField(
        widget=forms.NumberInput(
            attrs={'id': 'price', name="number"}
        )
    )

See the documentation on widgets .

    
answered by 21.04.2016 / 20:41
source