Modèle:radio comme filtre recherche
<form method="POST" action="/Bycategory/">
<input type="radio" name="andor1" value=1 checked>
<input type="radio" name="andor1" value=2>
<select id="pathology_id" name="pathology_id">
{% for pathology in pathology_list %}
<option value="{{ pathology.id }}">{{ pathology.pathology }}</option>
{% endfor %}
</select>
Il y a en fait trois recherche sélectionne (pathologie, matières premières, la technologie ) L'utilisateur peut faire et/ou pour un mélange ou d'un match de le trois, qui est pourquoi j'ai besoin de l'option et/ou dans le views.py.
Le views.py:
def Bypub(request):
andor1 = request.POST['andor1']
pathology_id = request.POST['pathology_id']
p = get_object_or_404(Pathology, pk=pathology_id)
pub1=Publication.objects.exclude(pathpubcombo__pathology__id= 1).filter(pathpubcombo__pathology=p)
list=[]
andlist=[]
for publication in pub1:
if andor1 == 1:
if publication not in list:
list.append(publication)
if andor1 == 2:
if publication in list:
andlist.append(publication)
#list=andlist
return render_to_response('search/categories.html', {
'andor1' : andor1,
'pub1': pub1,
'pathology': p,
'list' : list,
'andlist' : andlist,
},
context_instance=RequestContext(request)
)
Je sais que tout mon code fonctionne sans erreur, mais la ligne (si andor1 == 1 :) et (si andor1 == 2 :) est d'être ignoré. Je soupçonne que la valeur pour andor1 n'apparaît pas au point où je l'utilise. Je pense qu'il ne rend pas réellement qu'après le retour render_to_response, parce qu'il apparaît dans le modèle suivant comme valeur, sinon je verrais une sorte de réponse à l'if etor1 == 1: dans le modèle. Aucune suggestion?
Veuillez modifier votre question: Utilisez une indentation de 4 espaces pour les exemples de code. –
Vous pouvez facilement y parvenir en sélectionnant le code dans le champ de texte EDIT et en appuyant sur Ctrl + K –