Hi,
I want a user to select a multiple filter through check boxes.
The problem is that filtering in django doesn't return all the expected
results. I tried both chained filtering and filters with anded
conditions and the result is no different.
I'm I missing something? Where's the flaw?
--------- view----
def consultarFiltradasFiscalizacao(request):
user = request.user
r = Fiscalizacao()
r.exercicio_2002 = request.GET.get('exercicio_2002', None)
r.exercicio_2003 = request.GET.get('exercicio_2003', None)
r.exercicio_2004 = request.GET.get('exercicio_2004', None)
r.exercicio_2005 = request.GET.get('exercicio_2005', None)
filtros =
['exercicio_2002','exercicio_2003','exercicio_2004','exercicio_2005']
for f in filtros: setattr(r,f, \
getattr(r,f) == 'on' and 'true' or 'false')
print r.exercicio_2002
print r.exercicio_2003
print r.exercicio_2004
print r.exercicio_2005
#fichas = Fiscalizacao.objects.filter(exercicio_2002=r.exercicio_2002)\
#.filter(exercicio_2003=r.exercicio_2003)\
#.filter(exercicio_2004=r.exercicio_2004)\
#.filter(exercicio_2005=r.exercicio_2005)
fichas = Fiscalizacao.objects.filter(exercicio_2002=r.exercicio_2002).\
filter(exercicio_2005=r.exercicio_2005).\
filter(exercicio_2004=r.exercicio_2004).\
filter(exercicio_2003=r.exercicio_2003)
fichas = fichas.order_by('id')
return render_to_response('fichas/fiscalizacao/todas.html', \
{"fichas": fichas,"user":user})
--------- output of the django server---------------------
7543
false
true
true
false
[06/Sep/2006 17:44:36] "GET
/fichas/fiscalizacao/consultar_filtradas/?exercicio_2003=on&exercicio_2004=on
HTTP/1.1" 200 5472
5 fichas returned <--- this is INCORRECT
----------- postgreSQL--------------------
In postgresql, when I try to select the same query, I get eight results,
which is correct.
# select id from fichas_fiscalizacao where exercicio_2004 = true and
exercicio_2003 = true and exercicio_2002 = false;
id
----
6
5
4
7
9
11
10
8
(8 rows)
---------- template ----------------------
The template has no filtering:
{% block content-main %}
<div class="module">
{% if fichas %}
<table>
<tr>
{% for ficha in fichas %}
<td>{{ ficha.id }}</a></td>
<td>{{ ficha.inspeccionar_nif }}</a></td>
<td>{{ ficha.inspeccionar_nif_fk.nome|truncatewords:"2" }}</a></td>
<td>{{ ficha.data|date:"Y-m-d" }}</a></td>
{% if ficha.utilizador.first_name %}
<td>{{ ficha.utilizador.first_name }} {{
ficha.utilizador.last_name }}</a></td>
{% else %}
<td>{{ ficha.utilizador }}</a></td>
{% endif %}
<td><a href="/fichas/fiscalizacao/rever/{{ ficha.id }}"
class="changelink">Rever</a></td>
</tr>
{% endfor %}
</table>
{% else %}
Não há fichas arquivadas.
{% endif %}
</div>
Thanks for any help,
Luis
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---