django, change the value of a form field when I select items in another field

0

I have a form that registers a sale, I select the customer, the official (seller), and the items (products) sold and I am putting the total value of the sale manually. What I would like was that in selecting the items, somehow the price of each item was added up and the total amount automatically played in the field value of the sale ... how can I do that?

# form: 

class VendaForm(forms.ModelForm):
    class Meta:
        model = Venda
        fields = ('cliente', 'func', 'valor', 'itens')

# view:

def efetuar_venda(request):
    if request.method == 'POST':
        form = VendaForm(request.POST)
        if form.is_valid():
            venda = form.save()
            venda.save()
            return redirect('/calcados/', {})
    else:
        form = VendaForm()
        return render(request, 'calcados/cadastrar.html', {'form': form})

# the template cadastrar.html only shows the form given
    
asked by anonymous 16.06.2015 / 19:32

0 answers