Created
August 22, 2015 23:13
-
-
Save fandrefh/28df17224e97df80222a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#views.py | |
def home(request): | |
res_list = Restaurante.objects.all() | |
paginator = Paginator(res_list, 9) | |
page = request.GET.get('page') | |
try: | |
res = paginator.page(page) | |
except PageNotAnInteger: | |
res = paginator.page(1) | |
except EmptyPage: | |
res = paginator.page(paginator.num_pages) | |
return render(request, 'core/index.html', {'res': res}) | |
#templates | |
<div class="container"> | |
{% block itens %} | |
{% for r in res %} | |
{% for p in r.produto.all %} | |
<div class="col-md-4 col-sm-6 portfolio-item"> | |
<img class="img-responsive img-divug" alt="{{ p.produto }}" title="{{ r.restaurante }} | {{ p.produto }}" src="{{ p.foto_produto.url }}"></img> | |
<h6 class="text-img-divug3"><b> | |
{% if p.preco_normal == p.preco_promocao %} | |
0 | |
{% else %} | |
{{ p.desconto|floatformat:2 }} | |
{% endif %} | |
<span>%</span></b></h6> | |
<h6 class="text-img-divug"><b>{{ p.produto }}</b></h6> | |
<h5 class="text-img-divug2">{{ r.restaurante }}</h5> | |
<div class="navbar divug-v"> | |
{% if p.preco_normal and p.preco_promocao %} | |
<div class="p-divug"> | |
{% ifnotequal p.preco_normal p.preco_promocao %} | |
<h5>de <del>R$ {{ p.preco_normal|floatformat:2 }}</del> por</h5> | |
{% endifnotequal %} | |
<h2>R$ <b>{{ p.preco_promocao|floatformat:2 }}</b></h2> | |
</div> | |
{% endif %} | |
<button type="button" class="btn" data-toggle="modal" data-target="#meuModal-{{ p.id }}"><b>Detalhes</b></button> | |
</div> | |
<!--Modal--> | |
{% include "core/modal_detalhes.html" %} | |
</div> | |
{% endfor %} | |
{% endfor %} | |
</div> | |
{% endblock itens %} | |
<div class="container"> | |
<nav> | |
<ul class="pager"> | |
{% if res.has_previous %} | |
<li class="previous"><a href="?page={{ res.previous_page_number }}"><span aria-hidden="true">←</span> Voltar</a></li> | |
{% endif %} | |
{% if res.has_next %} | |
<li class="next"><a href="?page={{ res.next_page_number }}">Próxima <span aria-hidden="true">→</span></a></li> | |
{% endif %} | |
</ul> | |
</nav> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment