Add top tags

This commit is contained in:
Nyymix 2025-03-01 23:29:19 +02:00
parent 555c6c0d89
commit 669f9b999b
2 changed files with 38 additions and 0 deletions

View file

@ -1,4 +1,5 @@
{% extends "base_dark.html" %} {% extends "base_dark.html" %}
{% load top_tags %}
<!-- Title --> <!-- Title -->
{% block title %} Gallery {% endblock %} {% block title %} Gallery {% endblock %}
@ -7,6 +8,20 @@
{% block content %} {% block content %}
Hello World! Hello World!
<ul>
{% last_albums as albums %}
{% for album in albums %}
<li>{{ album.name }}</li>
{% endfor %}
</ul>
<ul>
{% top_photos as photos %}
{% for photo in photos %}
<li>{{ photo.views }} {{ photo.likes }} {{ photo.is_favorite }} {{ photo }}</li>
{% endfor %}
</ul>
<p>Istunto vanhenee: {{ session_expiry|date:"d.m.Y H:i" }}</p> <p>Istunto vanhenee: {{ session_expiry|date:"d.m.Y H:i" }}</p>
{% endblock %} {% endblock %}

View file

@ -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