From 669f9b999b9307834ba235b6388dbbfb81a09fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9DNyymix=E2=80=9D?= Date: Sat, 1 Mar 2025 23:29:19 +0200 Subject: [PATCH] Add top tags --- gallery/templates/gallery/main.html | 15 +++++++++++++++ gallery/templatetags/top_tags.py | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 gallery/templatetags/top_tags.py diff --git a/gallery/templates/gallery/main.html b/gallery/templates/gallery/main.html index 691afed..6da4000 100644 --- a/gallery/templates/gallery/main.html +++ b/gallery/templates/gallery/main.html @@ -1,4 +1,5 @@ {% extends "base_dark.html" %} +{% load top_tags %} {% block title %} Gallery {% endblock %} @@ -7,6 +8,20 @@ {% block content %} Hello World! + + + +

Istunto vanhenee: {{ session_expiry|date:"d.m.Y H:i" }}

{% endblock %} \ No newline at end of file diff --git a/gallery/templatetags/top_tags.py b/gallery/templatetags/top_tags.py new file mode 100644 index 0000000..94ee617 --- /dev/null +++ b/gallery/templatetags/top_tags.py @@ -0,0 +1,23 @@ +from django import template + +from gallery.models import Album, Photo + +register = template.Library() + + +@register.simple_tag +def last_albums(count=5): + albums = Album.objects.filter(is_public=True).order_by("-album_date")[:count] + return albums + + +@register.simple_tag +def top_photos(count=5): + photos = Photo.objects.filter(album__is_public=True).order_by('-is_favorite', '-likes', '-views').select_related('album')[:count] + return photos + + +@register.simple_tag +def top_photos_in_album(album, count=5): + photos = Photo.objects.filter(album=album).order_by('-is_favorite', '-likes', '-views').select_related('album')[:count] + return photos