Show number of search results
This commit is contained in:
parent
aa3b2fdd7b
commit
c369fbac1e
|
@ -4,7 +4,10 @@ from .models import Recette
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(forms.Form):
|
class SearchForm(forms.Form):
|
||||||
text = forms.CharField(widget=forms.TextInput(attrs={'autofocus': True}))
|
text = forms.CharField(
|
||||||
|
widget=forms.TextInput(attrs={'autofocus': True}),
|
||||||
|
required=False
|
||||||
|
)
|
||||||
saison = forms.ChoiceField(choices=(('all', "Toutes"),) + Recette.SAISON_CHOICES)
|
saison = forms.ChoiceField(choices=(('all', "Toutes"),) + Recette.SAISON_CHOICES)
|
||||||
veget = forms.BooleanField(label="Végétarien", required=False)
|
veget = forms.BooleanField(label="Végétarien", required=False)
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
div.results { margin-top: 1em; }
|
||||||
div.photo { float: right; }
|
div.photo { float: right; }
|
||||||
div.photo img { max-width: 100%; }
|
div.photo img { max-width: 100%; }
|
||||||
|
|
|
@ -7,10 +7,16 @@ from .models import Recette
|
||||||
def home(request):
|
def home(request):
|
||||||
form = SearchForm(request.POST or None)
|
form = SearchForm(request.POST or None)
|
||||||
recettes = []
|
recettes = []
|
||||||
|
num_results = None
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
recettes = form.search()
|
recettes = form.search()
|
||||||
|
num_results = recettes.count()
|
||||||
|
|
||||||
return render(request, 'index.html', context={'form': form, 'recettes': recettes})
|
return render(request, 'index.html', context={
|
||||||
|
'form': form,
|
||||||
|
'recettes': recettes,
|
||||||
|
'num_results': num_results,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def recette(request, pk):
|
def recette(request, pk):
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
<button>Rechercher</button>
|
<button>Rechercher</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% if num_results is not None %}
|
||||||
|
<div class="results">{{ num_results }} résultat(s)</div>
|
||||||
|
{% endif %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for recette in recettes %}
|
{% for recette in recettes %}
|
||||||
<li><a href="{{ recette.get_absolute_url }}">{{ recette.nom }}</a></li>
|
<li><a href="{{ recette.get_absolute_url }}">{{ recette.nom }}</a></li>
|
||||||
|
|
Loading…
Reference in a new issue