JeronimoC23 / biblioteca-bayer-Django

0 stars 0 forks source link

Fav de articulos #40

Closed JeronimoC23 closed 3 years ago

JeronimoC23 commented 3 years ago

Que los articulos que elles destaquen aparezcan primeros en el index y en las paginas particulares de las subcomisiones

JeronimoC23 commented 3 years ago

Resuelto con la view: def index(request): today = datetime.today() events = Event.objects.filter(public=True, fecha__gte = today) articles = Article.objects.filter(public=True) subcoms = SubCom.objects.all() fav_articles = Article.objects.filter(fav=True, public=True)

return render(request,'mainapp/index.html',{
    'title':'Home',
    'events':events,
    'articles': articles,
    'subcoms':subcoms,
    'fav_articles':fav_articles,

})

Y en la template:

BLOG

{% if fav_articles|length > 0%} {%for article in fav_articles|slice:2 %}
{% thumbnail article.image "360x225" crop="center" as im %} bulletin blog {% endthumbnail %}

{{article.title}}

{{article.created_at|date:'d/m/Y '}} {{article.author}}

{{article.content|safe|truncatechars_html:450}}
★ Articulo recomendado ★ {% comment %}

★ Articulo recomendado ★

{% endcomment %}
{%endfor %} {%for article in articles|slice:2 %}
{% thumbnail article.image "360x225" crop="center" as im %} bulletin blog {% endthumbnail %}

{{article.title}}

{{article.created_at|date:'d/m/Y '}} {{article.author}}

{{article.content|safe|truncatechars_html:450}}
Leer articulo →
{%endfor %} {% else %} {%for article in articles|slice:4 %}
{% thumbnail article.image "360x225" crop="center" as im %} bulletin blog {% endthumbnail %}

{{article.title}}

{{article.created_at|date:'d/m/Y '}} {{article.author}}

{{article.content|safe|truncatechars_html:450}}
Leer articulo →
{%endfor %} {%endif%}