Thursday, October 25, 2012

How can I compare the value of an aggregate with a list of results from a model

my view:
def comprar(request):
if request.method == 'POST':
form = FormComprar(request.POST)
if form.is_valid():
form = form.save()
retorno = 'Intenção de compra computada.'
form = FormComprar()
else:
form = FormComprar()
total =
Compra.objects.all().aggregate(quantidade_total=Sum('quantidade'))
[ 1 ]
valores = Valor.objects.all().order_by('quantidade') [ 2 ]
return render_to_response(
'form_compra.html',
locals(),
context_instance=RequestContext(request))


template - form_compra.html

Aggregate
{{ total.quantidade_total }} [ 1 ]

{% for valor in valores %}
{{ valor.quantidade }}
{% endfor %}
list os results [ 2 ]
e.g
1000
2000
3000

like a :

{% if total.quantidade_total >= {{ valor.quantidade }}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate