Add top tags
This commit is contained in:
parent
555c6c0d89
commit
669f9b999b
2 changed files with 38 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
{% extends "base_dark.html" %}
|
||||
{% load top_tags %}
|
||||
|
||||
<!-- Title -->
|
||||
{% block title %} Gallery {% endblock %}
|
||||
|
@ -7,6 +8,20 @@
|
|||
{% block content %}
|
||||
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>
|
||||
|
||||
{% endblock %}
|
23
gallery/templatetags/top_tags.py
Normal file
23
gallery/templatetags/top_tags.py
Normal 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
|
Loading…
Add table
Reference in a new issue