categorias

This commit is contained in:
jp.dev 2020-11-23 15:47:35 -03:00
parent 1dcc4909af
commit d0baa42cf6
4 changed files with 72 additions and 2 deletions

View File

@ -17,11 +17,30 @@
<span class="section-heading-upper">{{entrada.titulo}}</span> <span class="section-heading-upper">{{entrada.titulo}}</span>
<span class="section-heading-lower" style="color: Tomato;">{{entrada.contenido}}</span> <span class="section-heading-lower" style="color: Tomato;">{{entrada.contenido}}</span>
</h2> </h2>
<div style="text-align: left; font-size: 0.8em ">
Autor: {{entrada.autor}}
</div>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
{% endfor %} {% endfor %}
<section>
<div style="width:60%; background-color:Tomato; margin:auto; text-align:center;">
Categorías :
{% for entrada in entradas %}
{% for categoria in entrada.categorias.all %}
{{categoria.nombre}} &nbsp;&nbsp;&nbsp;
{% endfor %}
{% endfor %}
</div>
</section>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,46 @@
{% extends 'ProyectoWebApp/base.html' %}
{% load static %}
{% block content %}
{% for entrada in entradas %}
<!-- Heading -->
<section class="page-section clearfix">
<div class="container">
<div class="intro">
<img class="intro-img img-fluid mb-3 mb-lg-0 rounded" src="{{entrada.imagen.url}}" alt="" style="width: 70%;">
<div class="intro-text left-0 text-center bg-faded p-5 rounded">
<h2 class="section-heading mb-4" >
<span class="section-heading-upper">{{entrada.titulo}}</span>
<span class="section-heading-lower" style="color: Tomato;">{{entrada.contenido}}</span>
</h2>
<div style="text-align: left; font-size: 0.8em ">
Autor: {{entrada.autor}}
</div>
</div>
</div>
</div>
</section>
{% endfor %}
<section>
<div style="width:60%; background-color:Tomato; margin:auto; text-align:center;">
Categorías :
{% for entrada in entradas %}
{% for categoria in entrada.categorias.all %}
{{categoria.nombre}} &nbsp;&nbsp;&nbsp;
{% endfor %}
{% endfor %}
</div>
</section>
{% endblock %}

View File

@ -6,5 +6,6 @@ from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('', views.blog, name ='Blog'), path('', views.blog, name ='Blog'),
path('categoria/<int:categoria_id>/', views.categoria, name = 'categoria'),
] ]

View File

@ -1,9 +1,13 @@
from django.shortcuts import render from django.shortcuts import render
from blog.models import Entrada from blog.models import Entrada, Categoria
# Create your views here. # Create your views here.
def blog(request): def blog(request):
entradas = Entrada.objects.all() entradas = Entrada.objects.all()
return render(request, "blog/blog.html", {"entradas":entradas}) return render(request, "blog/blog.html", {"entradas":entradas})
def categoria(request, categoria_id):
categoria = Categoria.objects.get( id=categoria_id )
entrada = Entrada.objects.filter( categorias = categoria )
return render(request, "blog/categorias.html", {'categoria':categoria, 'entradas':entrada})