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

2012-10-25 Thread Érico Oliveira
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



where the syntax error?

2013-01-14 Thread Érico Oliveira
class Imovel(models.Model):
disponivel = models.BooleanField(choices=DISPO)
data_venda =  models.DateTimeField(auto_now_add=True, blank=True)

def validaData(self):
if self.data_venda < datetime.now - timedelta(days=2) <-

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



votes/score

2013-11-14 Thread Érico Oliveira
Hy, i'm learning django.
My idea is to give marks / votes for a selected job.
Works but not as I would.

class Job(models.Model):
title= models.CharField(max_length=20)
slug = models.SlugField(max_length=40, blank=True)
def __unicode__(self):
return self.title  


class Vote(models.Model):
job = models.ForeignKey(Job)
score = models.IntegerField(blank=True, default=0)


my forms.py

MYVALUES = (
(5, u'5 '), # don't work {{ 
form|safe }}
(5, five'),
(3, u'three'),
(2, u'two'), 
(1, u'one'),
)
class FormVote(forms.ModelForm):
class Meta:
model = Vote
score = forms.ChoiceField(choices=MYVALUES, widget=forms.RadioSelect())



As I did all the html / css. I would not return the form that way.
I tried a different approach, trying to pass the values of the vote 
through a link using jquery, but I can not mount the garvar to view the 
value of voting.

It would be a mess trying to return an HTML inside FormVote, something like:







Help?
thanks in advance.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/736728d8-dc12-41aa-b223-7c8bed0a2cf4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.